HTTP / 2 PYTHON AttributeError:'NoneType'对象没有属性'write'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTTP / 2 PYTHON AttributeError:'NoneType'对象没有属性'write'相关的知识,希望对你有一定的参考价值。

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()

以上是关于HTTP / 2 PYTHON AttributeError:'NoneType'对象没有属性'write'的主要内容,如果未能解决你的问题,请参考以下文章

Python 报错 AttributeError: module 'django.db.models' has no attribute 'SubfieldBase'(

Python 数据分析module ‘numpy‘ has no attribute ‘array‘

python 中json has no attribute 'loads'

appium+python自动化34-获取元素属性get_attribute

ubuntu python opencv3 cv2.cv2 has no attribute 'face' 'cv2.face' has no attribute

python提示AttributeError: 'NoneType' object has no attribute 'append'