Python requests.exceptions.SSLError: EOF occurred in violation of protocol

前端 未结 6 1765
长发绾君心
长发绾君心 2020-12-06 01:43

I would retrieve some information from an ABB G13 gateway that offer a RESTful JSON API. API is hosted by the gateway via https endpoint. Basic authentication mechanism is u

相关标签:
6条回答
  • 2020-12-06 01:55

    Step 1: Check that Python supports TLS 1.1

    You may have a Python setup that only supports TLS 1.0 – not TLS 1.1 or above.

    You can check it like this:

    Python 3

    from urllib.request import urlopen
    urlopen('https://www.howsmyssl.com/a/check').read()
    

    Python 2

    from urllib2 import urlopen
    urlopen('https://www.howsmyssl.com/a/check').read()
    

    (If you get urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)> you may have to disable certificate verification. NOTE: doing this will disable SSL protections against evildoers who would impersonate or intercept traffic to that website - see https://en.wikipedia.org/wiki/Man-in-the-middle_attack )

    import ssl
    urlopen('https://www.howsmyssl.com/a/check', context=ssl._create_unverified_context()).read()
    

    Check the output for the key tls_version. If it says TLS 1.0 and not TLS 1.1 or TLS 1.2 that could be the problem.

    If you're using a virtualenv, be sure to run the command inside.

    Step 2: Install Python with a newer version of OpenSSL

    In order support TLS 1.1 or above, you may need to install a newer version of OpenSSL, and the install Python again afterwards. This should give you a Python that supports TLS 1.1.

    The process depends on your operating system – here's a guide for OS X.

    virtualenv users
    For me, the Python outside of my virtualenv had TLS 1.2 support, so just I removed my old virtualenv, and created a new one with the same packages and then it worked. Easy peasy!

    0 讨论(0)
  • 2020-12-06 02:01

    I had exactly the same error, turns out that I didn't have ndg-httpsclient installed, see my original issue raised in github.

    0 讨论(0)
  • 2020-12-06 02:03

    This thing worked for me, just make sure whether these modules are installed or not, if not then install them, following are:

    pip install ndg-httpsclient
    
    pip install pyopenssl
    
    pip install pyasn1
    

    It removed my SSLError: EOF occurred in violation of protocol (_ssl.c:590) error.

    Hope it helps.

    0 讨论(0)
  • 2020-12-06 02:03

    I found it was going through a proxy when it should have connected to the server directly.

    I fixed this by doing

    unset https_proxy
    
    0 讨论(0)
  • 2020-12-06 02:17

    If you are getting this error for intermediate requests, you can refer to the solution mentioned in https://github.com/requests/requests/issues/3391.

    Basically, if you are making a lot of requests to a server and facing this issue with some of those requests you can use Session to just retry the requests.

    Let me know if this works.

    0 讨论(0)
  • 2020-12-06 02:20

    The only time I have seen errors of this nature have been times that I was using requests to screen scrape data and I was using a multiprocessing library. I would either try your code without the pool manager or split your app into two apps, one that doles out urls and another that consumes them.

    The client-server pair here should give you some ideas. I was able to scale my client out horizontally when I used the hacky server code to load all urls into a Queue in memory just before app.run. Hope that helps.

    0 讨论(0)
提交回复
热议问题