HTTP / 2是万维网使用的HTTP网络协议的主要修订。 HTTP / 2的主要目标是通过启用完整的请求和响应多路复用来减少延迟,通过有效压缩HTTP标头字段来最小化协议开销,并增加对请求优先级和服务器推送的支持。
[我正在尝试使用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())
HTTP / 2是万维网使用的HTTP网络协议的主要修订。 HTTP / 2的主要目标是通过启用完整的请求和响应多路复用来减少延迟,将...
HTTP / 2使用self.channel
写入响应。因此,将self.transport.write()
更改为self.channel.write()
。