【问题标题】:python-requests 2.0.0 - [Errno 8] _ssl.c:504: EOF occurred in violation of protocolpython-requests 2.0.0 - [Errno 8] _ssl.c:504: EOF 发生违反协议
【发布时间】:2013-10-16 09:40:05
【问题描述】:

我正在使用 Requests 2.0.0,但未能完成 https GET 请求:

requests.get('https://backend.iddiction.com/rest/v1/s2s/confirm_install?apphandle=slotsjourneyofmagic&appsecret=5100d103e146e2c3f22af2c24ff4e2ec&mac=50:EA:D6:E7:9B:C2&idfa=134DA32A-A99F-4864-B69E-4A7A2EFC6C25')

我收到此错误:

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

我在网上和这个网站上阅读了很多内容,但我阅读的每一个地方都说这些问题在 2.0.0 版中得到了修复。

谁能给点建议?

【问题讨论】:

    标签: python https python-requests


    【解决方案1】:

    服务器要求您使用 SNI,这在 Python 2.x 中通常不可用。

    如果您在浏览器中打开该 URL 并使用 Wireshark 跟踪 TLS 握手,您可以看到 Chrome 建议服务器名称,并且远程服务器使用它来确定要使用的证书。

    要在 Requests 中进行这项工作,您可以使用 Python 3,它包括 SNI 支持并且 Requests 将透明地使用哪些,或者您可以在 Python 2.x 中的 Requests from this answer 中安装 SNI 所需的依赖项:

    • pyopenssl
    • ndg-httpsclient
    • pyasn1

    这些解决方案中的任何一个都可以使您的代码正常工作。

    【讨论】:

    • 非常感谢。完美运行。
    猜你喜欢
    • 1970-01-01
    • 2012-12-15
    • 2012-07-31
    • 1970-01-01
    • 2015-05-13
    • 2016-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多