我在运行hyper
增加对HTTP/2
协议的支持的 Python 库时遇到问题。
在我的 Fedora 机器上,我安装了它pip
并pip3
与 Python 2.7.8 和 Python 3.4.1 一起使用。然后我复制了与 twitter 连接的测试脚本:
from hyper import HTTP20Connection
conn = HTTP20Connection('twitter.com:443')
conn.request('GET', '/')
resp = conn.getresponse()
print(resp.read())
我使用 Python 2.7.8 运行它并以错误结束:
[mn:/plib] 1 ‡ python hyper_test.py
Traceback (most recent call last):
File "hyper_test.py", line 4, in <module>
conn.request('GET', '/')
File "/usr/lib/python2.7/site-packages/hyper/http20/connection.py", line 149, in request
self.endheaders(message_body=body, final=True, stream_id=stream_id)
File "/usr/lib/python2.7/site-packages/hyper/http20/connection.py", line 310, in endheaders
self.connect()
File "/usr/lib/python2.7/site-packages/hyper/http20/connection.py", line 215, in connect
self._recv_cb()
File "/usr/lib/python2.7/site-packages/hyper/http20/connection.py", line 580, in _recv_cb
self._consume_single_frame()
File "/usr/lib/python2.7/site-packages/hyper/http20/connection.py", line 496, in _consume_single_frame
frame, length = Frame.parse_frame_header(header)
File "/usr/lib/python2.7/site-packages/hyper/http20/frame.py", line 52, in parse_frame_header
frame = FRAMES[type](stream_id)
KeyError: 80
它以 Python 3.4.1 的不同错误结束:
[mn:/plib] 1 ‡ python3 hyper_test.py
Traceback (most recent call last):
File "hyper_test.py", line 4, in <module>
conn.request('GET', '/')
File "/usr/lib/python3.4/site-packages/hyper/http20/connection.py", line 149, in request
self.endheaders(message_body=body, final=True, stream_id=stream_id)
File "/usr/lib/python3.4/site-packages/hyper/http20/connection.py", line 310, in endheaders
self.connect()
File "/usr/lib/python3.4/site-packages/hyper/http20/connection.py", line 204, in connect
sock = wrap_socket(sock, self.host)
File "/usr/lib/python3.4/site-packages/hyper/http20/tls.py", line 44, in wrap_socket
assert ssl_sock.selected_npn_protocol() in H2_NPN_PROTOCOLS
AssertionError
什么会导致我的环境出现此类问题?