socket.error: [Errno 54] Connection reset by peer
See original GitHub issueI’m currently getting the error, socket.error: [Errno 54] Connection reset by peer
when I use requests.get(url, params=kwargs)
and the params
contain large bodies of text. If I truncate the two large bodies of text to less than 2,900 characters each, it works. If I run the same get request from the command line using curl
it works. I’m using requests version 0.6.1 that I installed using, pip install python-requests
.
I’m not sure how to tell you to replicate the issue because I’m using the python-sendgrid library to add a newsletter to my sendgrid account and I don’t want to post my api username and password in issue ticket. 😃
To test from the command line using curl I created two files that each contained plain text and html text that was urlencoded using a urlencoder. Then I ran the following command.
export IDENTITY='<my identity number>'
export API_KEY='<my smtp password>'
export API_USER='<my smtp username>'
export NAME='<My Urlencoded Newsletter Name>'
export SUBJECT='<My Urlencoded Newsletter Subject>'
TEXT=`cat urlencoded.txt`; HTML=`cat urlencoded.html`; curl -d "api_user=$API_USER&api_key=$API_KEY&identity=$IDENTITY&name=$NAME&subject=$SUBJECT&text=$TEXT&html=$HTML" https://sendgrid.com/api/newsletter/newsletter/add.json
Issue Analytics
- State:
- Created 12 years ago
- Comments:19 (14 by maintainers)
Sweet action! Switching from
requests.get(url, params=kwargs)
torequests.post(url, data=kwargs)
fixed it! Sorry for bother you with this and thanks for the help!If you take the time to take a look at the two requests through Charles (or similar), I’m sure you’ll see the issue quite quickly.
As the error says, the Request-URI is too large for the server to process, so it’s dropping the connection.
With Requests, you’re sending all the data as a massive query string in the Request URI, known as a GET parameter. When you’re using curl, you’re uploading form-encoded data to the body of the request, known as POST data.