question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

socket.error: [Errno 54] Connection reset by peer

See original GitHub issue

I’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:closed
  • Created 12 years ago
  • Comments:19 (14 by maintainers)

github_iconTop GitHub Comments

5reactions
epicservecommented, Sep 22, 2011

Sweet action! Switching from requests.get(url, params=kwargs) to requests.post(url, data=kwargs) fixed it! Sorry for bother you with this and thanks for the help!

5reactions
kennethreitzcommented, Sep 22, 2011

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 'Connection reset by peer' - sockets - Stack Overflow
The error "Connection reset by peer" on a UDP socket, means the client has received an ICMP error message (for example: port unreachable, ......
Read more >
ConnectionResetError: Errno 54 Connection reset by peer
This message indicates the remote site - here, the client, your browser - reset the connection before the response could be fully sent....
Read more >
[Errno 54] Connection reset by peer - API Issues
Since it looks like the connection is being terminated from the Remote side do you have any transparent proxy servers between yourself and...
Read more >
Getting "socket.error: [Errno 54] Connection reset by peer ...
Getting "socket.error: [Errno 54] Connection reset by peer" when trying to connect to REST API using Python lib.
Read more >
ConnectionResetError: [Errno 54] Connection reset by peer.
It is an issue related with sockets maybe antivirus or firewall blocks connections, it is hard to tell. Please don't use trac as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found