Назад | Перейти на главную страницу

'Python' Twisted Post Requests AttributeError: объект 'NoneType' не имеет атрибута 'write'

Я пытаюсь реализовать простой сервер с клиентом, использующим 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())