Python client error 'Connection reset by peer'
While installing requests
library it skips few of optional security packages ('pyOpenSSL', 'ndg-httpsclient', and 'pyasn1') which are required for the SSL/Https connection.
You can fix it by either running this command
pip install "requests[security]"
or
pip install pyopenssl ndg-httpsclient pyasn1
Installing the optional security packages did not work for me, just in case someone as the same error message, check that the url you are trying to use is correct.
For instance if the server expects a connection on a different port, it is possible you find this error.
I tried installing all the optional security packages provided in the answer above. But nothing seemed to work.
One important GOTCHA : Check if your url end-point actively prevents programmatic access.
Take a look at the robots.txt file in the root directory of a website: http://myweburl.com/robots.txt.
If it contains text that looks like this : User-agent: * Disallow: /
This site doesn’t like and want scraping. This gives you the same dreaded error 54, connection reset by the peer.
Here is a snapshot :
https://www.aclibrary.org/robots.txt
User-agent: discobot Disallow: / User-agent: AddThis.com Disallow: / User-agent: Yandex Disallow: / User-agent: Baiduspider Disallow: / User-agent: Baiduspider-video Disallow: / User-agent: Baiduspider-image Disallow: / User-agent: SemrushBot Disallow: / User-agent: SemrushBot-SA Disallow: / User-Agent: W3C-checklink Crawl-delay: 0 User-agent: Twitterbot Disallow: User-agent: * Crawl-delay: 10 Disallow: /er.php Disallow: /err.php Disallow: /go.php Disallow: /friendly.php Disallow: /ld.php Disallow: /srch.php Sitemap: https://aclibrary.org/sitemap.xml
I had the same problem, but installing the optional security packages did not work for me too.
I had to downgrade requests
version from 2.25.1
to 2.21.0