python-requests 2.0.0 - [Errno 8] _ssl.c:504: EOF occurred in violation of protocol

醉酒当歌 提交于 2020-01-01 03:35:28

问题


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')

I get this Error:

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

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?


回答1:


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

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.

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

Either of those solutions will make your code work correctly.



来源:https://stackoverflow.com/questions/19399975/python-requests-2-0-0-errno-8-ssl-c504-eof-occurred-in-violation-of-proto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!