python-requests 2.0.0 - [Errno 8] _ssl.c:504:EOF违反协议

问题描述:

我正在使用Requests 2.0.0并且无法使用以下内容完成https GET请求:

I'm using Requests 2.0.0 and failed to complete https GET request using:

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中修复了这些问题。

I read a lot of content on the web and on this site but every where i read it says that those problems fixed in version 2.0.0.

有人可以在这里建议吗?

Can anyone advice here?

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

The server requires that you use SNI, which isn't normally available in Python 2.x.

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

If you open that URL in a browser and use Wireshark to trace out the TLS handshake, you can see that Chrome proposes the server name and that the remote server uses it to determine which certificate to use.

要使其工作请求您可以使用Python 3,其中包括SNI支持以及哪些请求将透明地使用,或者您可以在请求中为Python 2.x中的SNI安装所需的依赖项来自这个答案

To make this work in Requests you can either use Python 3, which includes SNI support and which Requests will transparently make use of, or you can install the required dependencies for SNI in Python 2.x in Requests from this answer:


  • pyopenssl

  • ndg -httpsclient

  • pyasn1

Eit她的这些解决方案将使您的代码正常工作。

Either of those solutions will make your code work correctly.