python-hyper / hyper

HTTP/2 for Python.

Home Page:http://hyper.rtfd.org/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how can I connect nginx-1.11.5 by http2.0

moonlightheng opened this issue · comments

well I start a nginx-1.11.5
when I connect the server by chrome and FireFox
I can see the access.log as follows
"GET / HTTP/2.0" 200 728 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"

but when I use these code:

context = ssl._create_unverified_context()
conn = HTTPConnection('xxx.com', 8443, True, None, False, context)
conn.request('GET', '/index.html')
resp = conn.get_response()

I see the log
"GET /index.html HTTP/1.1" 200 612 "-" "-"

what is the deference between these too ways

thank you

Can you please provide me with the following information?

  • the output from python --version
  • the output from python -c "import ssl; print(ssl.OPENSSL_VERSION)"
  • the output from python -c "import platform; print(platform.platform())"
  • the output from pip freeze
  • the output from python -c "from cryptography.hazmat.backends.openssl import backend; print(backend.openssl_version_text())"

here are outputs

python --version
Python 2.7.12 :: Anaconda 2.5.0 (x86_64)
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2g 1 Mar 2016
python -c "import platform; print(platform.platform())"
Darwin-16.0.0-x86_64-i386-64bit
pip freeze
abstract-rendering==0.5.1
alabaster==0.7.7
anaconda-client==1.2.2
appnope==0.1.0
appscript==1.0.1
argcomplete==1.0.0
astropy==1.1.1
Babel==2.2.0
backports-abc==0.4
backports.shutil-get-terminal-size==1.0.0
backports.ssl-match-hostname==3.4.0.2
beautifulsoup4==4.4.1
bitarray==0.8.1
blaze==0.9.0
bokeh==0.11.0
boto==2.39.0
Bottleneck==1.0.0
catkin-pkg==0.2.10
cdecimal==2.3
cffi==1.2.1
clyent==1.2.0
colorama==0.3.6
conda-build==1.19.0
conda-env==2.5.0a0
configobj==5.0.6
cryptography==1.0.2
cssselect==0.9.1
cycler==0.9.0
Cython==0.23.4
cytoolz==0.7.5
datashape==0.5.0
decorator==4.0.6
docutils==0.12
dynd===f641248
empy==3.3.2
enum34==1.1.2
et-xmlfile==1.0.1
fastcache==1.0.2
Flask==0.10.1
funcsigs==0.4
futures==3.0.3
gevent==1.0.2
gevent-websocket==0.9.5
greenlet==0.4.9
grin==1.2.1
h2==2.4.1
h5py==2.5.0
hpack==2.3.0
hyper==0.7.0
hyperframe==3.2.0
idna==2.0
imagesize==0.7.1
ipaddress==1.0.14
ipykernel==4.2.2
ipython==5.1.0
ipython-genutils==0.1.0
ipywidgets==4.1.1
itsdangerous==0.24
jdcal==1.2
jedi==0.9.0
Jinja2==2.8
jsonschema==2.4.0
jupyter==1.0.0
jupyter-client==4.1.1
jupyter-console==4.1.0
jupyter-core==4.0.6
llvmlite==0.8.0
lxml==3.5.0
MarkupSafe==0.23
matplotlib==1.5.1
mistune==0.7.1
multipledispatch==0.4.8
nbconvert==4.1.0
nbformat==4.0.1
networkx==1.11
nltk==3.1
nose==1.3.7
notebook==4.1.0
numba==0.23.1
numexpr==2.4.6
numpy==1.10.4
odo==0.4.0
openpyxl==2.3.2
pandas==0.17.1
path.py==0.0.0
pathlib2==2.1.0
patsy==0.4.0
pep8==1.7.0
pexpect==3.3
pickleshare==0.5
Pillow==3.1.0
ply==3.8
prompt-toolkit==1.0.7
psutil==3.4.2
ptyprocess==0.5
py==1.4.31
pyasn1==0.1.9
PyAudio==0.2.7
pycosat==0.6.1
pycparser==2.14
pycrypto==2.6.1
pycurl==7.19.5.3
pyflakes==1.0.0
Pygments==2.1
PyMySQL==0.6.7
pyOpenSSL==0.15.1
pyparsing==2.0.3
pytest==2.8.5
python-dateutil==2.5.3
pytz==2015.7
PyYAML==3.11
pyzmq==15.2.0
qtconsole==4.1.1
queuelib==1.2.2
redis==2.10.3
requests==2.9.1
rope==0.9.4
rosdep==0.11.5
rosdistro==0.4.7
rosinstall==0.7.8
rosinstall-generator==0.1.11
rospkg==1.0.39
ruamel-yaml===-VERSION
scikit-image==0.11.3
scikit-learn==0.17.1
scipy==0.17.0
Scrapy==1.0.3
simplegeneric==0.8.1
singledispatch==3.4.0.3
six==1.10.0
snowballstemmer==1.2.1
sockjs-tornado==1.0.1
Sphinx==1.4.3
sphinx-rtd-theme==0.1.9
spyder==2.3.8
SQLAlchemy==1.0.11
statsmodels==0.6.1
sympy==0.7.6.1
tables==3.2.2
terminado==0.5
toolz==0.7.4
tornado==4.3
traitlets==4.2.2
Twisted==16.1.1
unicodecsv==0.14.1
urlgrabber==3.9.1
vcstools==0.1.38
w3lib==1.12.0
wcwidth==0.1.7
Werkzeug==0.11.3
wstool==0.1.13
xlrd==0.9.4
XlsxWriter==0.8.4
xlwings==0.6.4
xlwt==1.0.0
zope.interface==4.1.3
python -c "from cryptography.hazmat.backends.openssl import backend;

print(backend.openssl_version_text())"
OpenSSL 1.0.2g 1 Mar 2016

Ah, sorry, I see the problem.

You're using a context you created yourself, rather than ours. That means it doesn't do the protocol negotiation. Try changing your code to this:

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

conn = HTTPConnection('xxx.com', 8443, True, None, False, context)
conn.request('GET', '/index.html')
resp = conn.get_response()

That should resolve your issue.

@Lukasa yes you are right
that solve my problem
thank you a lot