本文介绍了urllib3关于Google App Engine上的python 2.7 SNI错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试从SNI托管的Google App Engine的我的网站上下载HTTPS页面。
无论使用什么库,我都会收到以下错误消息:

$ $ $ $ code $ Errno 8 _ssl.c:504 :EOF发生违反协议

我试过用很多方法解决错误,包括使用urllib3 openssl monkeypatch:

  from urllib3.contrib import pyopenssl 
pyopenssl.inject_into_urllib3

但是我总是得到上面提到的错误。



有什么想法吗? p>

解决方案

不幸的是,对于urllib3,Python标准库在Python 3.2之前没有添加SNI支持。
(请参阅)



要使用Python 2.7中的SNI和urllib3,您需要使用PyOpenSSL注入monkeypatch。
(请参阅)

  from urllib3.contrib import pyopenssl 
pyopenssl.inject_into_urllib3()

你的问题基本上有相同的代码,除了它在 pyopenssl.inject_into_urllib3()调用中缺少括号调用。解决这个问题应该有效。



您还需要确保提供以下依赖项:




  • pyOpenSSL(测试结果为0.13)
  • ndg-httpsclient(测试结果为0.3.2)
  • pyasn1与0.1.6)


I'm trying to download an HTTPS page from my site hosted on Google App Engine with SNI.No matter what library I use, I get the following error:

[Errno 8] _ssl.c:504: EOF occurred in violation of protocol

I've tried solving the error in many ways, including using the urllib3 openssl monkeypatch:

from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3

But I always get the same error mentioned above.

Any ideas?

解决方案

Unfortunately for urllib3, the Python standard library did not add SNI support until Python 3.2.(See Issue #118 @ urllib3)

To use SNI in Python 2.7 with urllib3, you'll need to use the PyOpenSSL injection monkeypatch.(See Issue #156 @ urllib3)

from urllib3.contrib import pyopenssl
pyopenssl.inject_into_urllib3()

Your question basically had the same code, except it was missing the parentheses call on the pyopenssl.inject_into_urllib3() call. Fixing that should do the trick.

You'll also need to make sure to have the following dependencies available:

  • pyOpenSSL (tested with 0.13)
  • ndg-httpsclient (tested with 0.3.2)
  • pyasn1 (tested with 0.1.6)

这篇关于urllib3关于Google App Engine上的python 2.7 SNI错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 19:25