python-hyper / hyper

HTTP/2 for Python.
http://hyper.rtfd.org/en/latest/
MIT License
1.05k stars 191 forks source link

An example of http2 based on ssl #369

Closed guoxiaolu closed 6 years ago

guoxiaolu commented 6 years ago

`from hyper import HTTP20Connection, tls from hyper.compat import ssl

context = tls.init_context() context.check_hostname = False context.verify_mode = ssl.CERT_NONE

conn = HTTP20Connection('https://127.0.0.1', 5000, ssl_context=context) conn.request('GET', '/') resp = conn.get_response()

print(resp.read())`

I want to test a http2 based on tls, and write an example, but it returns error like this: Traceback (most recent call last): File "hyper_test.py", line 13, in <module> conn.request('POST', '/') File "/home/lavector/http2/hyper/hyper/http20/connection.py", line 274, in request self.endheaders(message_body=body, final=True, stream_id=stream_id) File "/home/lavector/http2/hyper/hyper/http20/connection.py", line 560, in endheaders self.connect() File "/home/lavector/http2/hyper/hyper/http20/connection.py", line 374, in connect timeout=connect_timeout) File "/usr/lib/python2.7/socket.py", line 557, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno -2] Name or service not known

can you give me some suggestions?

Lukasa commented 6 years ago

The problem here is getaddrinfo call: are you sure the hostname you're looking up is correct? I will note that your example code does not match the traceback you provided.

guoxiaolu commented 6 years ago

I used a flask like http2 package 'Quart' to establish http2 server, and it only support tls. I don't know this problem is caused by the server or not. I will check it. As you said, it seems the example code has nothing wrong? what you said 'does not match' is an edit problem, 'conn.request('GET', '/')' I used 'GET'/'POST' methods, and both are error. I will check the server code, Thank you very much.