requests: error 54, 'Connection reset by peer'
I’m getting the dreaded Error 54, Connection reset by peer when trying to do a POST to a URL with a payment provider I’m using. Here is the basic code I’m running:
import requests, base64
url = "https://sandbox.api.mxmerchant.com/checkout/v3/auth/token/282059461"
headers = {
'Authorization': 'Basic ' + base64.b64encode('myusername:mypassword') ,
}
r = requests.post(url, headers=headers)
print r.text
If I run this exact code on an Ubuntu server it works fine (meaning it returns a json message stating that the username and password are incorrect).
If I run it on OSX 10.11.4, I get the connection reset error.
After reading a ton of issues on here and various postings on StackOverflow, everyone seems to think it’s related to SNI. Unfortunately, none of the recommendations that I’ve come across have fixed the issue.
My Ubuntu server has Python 2.7.6, OpenSSL 1.0.1f and requests 2.8.1.
My OSX has Python 2.7.10, OpenSSL 1.0.2g and requests 2.10.0. I also have ndg-httpsclient and pyopenssl both installed per #1347
Any idea what it is that I’m missing?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 3
- Comments: 16 (6 by maintainers)
@Bashar That specific list is now out of date. You should make sure you use
pip install requests[security]instead: that will always install the correct dependencies.Tried pip install pyopenssl ndg-httpsclient pyasn1 and also installed requests but still no result
For the sake of others like me coming to this issue by googling this exception:
I resolved this issue for myself by updating my system
virtualenvwrapperpackage to latest (sudo pip install -U virtualenvwrapper), which lifted myvirtualenvversion from 13.1.2 to 15.1.0. I then recreated the virtualenv for my project. I then executed the command that was giving me the error in the first place, and it completed successfully.