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.

Connection Reset by Peer

See original GitHub issue

Summary

While making an HTTPS GET request to fema.gov I get a Connection Reset Error, this is confirmed on multiple machines not to happen in Python 2 but does happen on Python 3, both are using the same version of requests. Very bizarrely (in this case) the failure occurs when trying to read the 3704 byte. (discovered by using lower level functions). Below is the URL:

https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer/16/query?where=&text=&objectIds=&time=&geometry=-9240000%2C4400000%2C-9230000%2C4410000&geometryType=esriGeometryEnvelope&inSR=102100&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&returnTrueCurves=false&resultOffset=&resultRecordCount=&f=pjson

Things I have tried:

  • User-Agent strings
  • Disabling verify
  • Using machines with different IP addresses
  • Matching all libraries except openssl_version to the working Python 2.7 environment

Reproduction Steps

python
import requests
url ="https://hazards.fema.gov/gis/nfhl/rest/services/public/NFHL/MapServer/16/query?where=&text=&objectIds=&time=&geometry=-9240000%2C4400000%2C-9230000%2C4410000&geometryType=esriGeometryEnvelope&inSR=102100&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=true&maxAllowableOffset=&geometryPrecision=&outSR=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&returnDistinctValues=false&returnTrueCurves=false&resultOffset=&resultRecordCount=&f=pjson"
response=requests.get(url)

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "2.2.2"
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.4"
  },
  "platform": {
    "release": "4.13.0-21-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1010008f",
    "version": "18.0.0"
  },
  "requests": {
    "version": "2.18.4"
  },
  "system_ssl": {
    "version": "1010006f"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}

As noted above the request works fine in Python 2.7

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "1.9"
  },
  "implementation": {
    "name": "CPython",
    "version": "2.7.14"
  },
  "platform": {
    "release": "4.13.0-21-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1000207f",
    "version": "16.2.0"
  },
  "requests": {
    "version": "2.18.1"
  },
  "system_ssl": {
    "version": "1000207f"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": true
}

I have tried to get the versions of my Python 3 to match but even doing this the request still fails in Python 3.

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "1.9"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.4"
  },
  "platform": {
    "release": "4.13.0-21-generic",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "1010006f",
    "version": "16.2.0"
  },
  "requests": {
    "version": "2.18.1"
  },
  "system_ssl": {
    "version": "1010006f"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": true
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
etothepiicommented, May 27, 2018

Hi Ian,

Thank you for you help, it is very much appreciated.

As discussed above I have satisfied the immediate problem by running curl in a sub process but that seems like a horrible solution.

I really appreciate your help and I agree with you that it works on some other setups. As evidenced by it working on Python 3. To me this suggests that it is most likely not the server that is at fault (as would be the normal response to a Connection Reset by Peer). Doesn’t it seem so very odd to you that I am able to make the request and get a 200 response using lower level functions but get the connection reset if trying to read past char 3704, despite the message clearly being 15000 chars long?

Please accept my apologies for the confusion above - with diagnostics. I was trying to show that I had already tried to align my non-working Python 3 system with a working Python 2 system, by showing what I had changed it to. As far as I can see I have managed to sync everything up between the working between them except for the system SSL version which is 1000207f (working) rather than 1010006f (non-working). Everything else is the same according to my version of Beyond Compare (image attached).

Any help or suggestions for further avenues of inquiry would be very welcome.

Kind regards,

James

image

0reactions
nateprewittcommented, Jun 12, 2018

Thanks for checking back in @etothepii. Since it doesn’t look like there is more information to work with, and this seems to be a local configuration issue, I’m going to close this out.

Please feel free to reopen if you have more information later. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "connection reset by peer" mean? - Stack Overflow
"Connection reset by peer" is the TCP/IP equivalent of slamming the phone back on the hook. It's more polite than merely not replying,...
Read more >
How To Fix the Error “Connection Reset by Peer” - Alphr
A “connection reset by peer” error means the TCP stream was closed, for whatever reason, from the other end of the connection.
Read more >
What is a TCP Connection Reset by Peer? | Pico
An application gets a connection reset by peer error when it has an established TCP connection with a peer across the network, and...
Read more >
Why do we get the error "Connection reset by peer ... - IBM
The error message "Connection reset by peer" appears, if the web services client was waiting for a SOAP response from the remote web...
Read more >
How to Fix The "Connection reset by peer" SSH Error
The “ssh_exchange_identification: read: Connection reset by peer” error indicates that the remote machine abruptly closed the Transition Control ...
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