HTTP / 2 PYTHON AttributeError: объект 'NoneType' не имеет атрибута 'write' - PullRequest
0 голосов
/ 03 февраля 2020

HTTP / 2 является основной версией сетевого протокола HTTP, используемого в World Wide Web. Основными целями для HTTP / 2 являются снижение задержки за счет включения полного мультиплексирования запросов и ответов, минимизации издержек протокола посредством эффективного сжатия полей заголовков HTTP и добавления поддержки приоритезации запросов и сервера pu sh

Я пытаюсь реализовать простой сервер с клиентом, использующим HTTP / 2. Я следовал приведенным здесь примерам https://python-hyper.org/projects/h2/en/stable/twisted-post-example.html# Однако каждый раз, когда я пытаюсь отправить файл с клиента на сервер, я получаю эта ошибка

AttributeError: 'NoneType' object has no attribute 'write'

Ошибка происходит из этой части кода

def sendFileData(self):
"""
Send some file data on the connection.
"""
# Firstly, check what the flow control window is for stream 1.
window_size = self.conn.local_flow_control_window(stream_id=1)

# Next, check what the maximum frame size is.
max_frame_size = self.conn.max_outbound_frame_size

# We will send no more than the window size or the remaining file size
# of data in this call, whichever is smaller.
bytes_to_send = min(window_size, self.file_size)

# We now need to send a number of data frames.
while bytes_to_send > 0:
    chunk_size = min(bytes_to_send, max_frame_size)
    data_chunk = self.fileobj.read(chunk_size)
    self.conn.send_data(stream_id=1, data=data_chunk)

    bytes_to_send -= chunk_size
    self.file_size -= chunk_size

# We've prepared a whole chunk of data to send. If the file is fully
# sent, we also want to end the stream: we're done here.
if self.file_size == 0:
    self.conn.end_stream(stream_id=1)
else:
    # We've still got data left to send but the window is closed. Save
    # a Deferred that will call us when the window gets opened.
    self.flow_control_deferred = defer.Deferred()
    self.flow_control_deferred.addCallback(self.sendFileData)
This line--> self.transport.write(self.conn.data_to_send())

1 Ответ

0 голосов
/ 04 февраля 2020

HTTP / 2 использует self.channel для записи ответа. Так что измените self.transport.write() на self.channel.write().

...