简体   繁体   中英

Python requests / urllib2 socket.error: [Errno 104] Connection reset by peer

I have the following code:

import requests

requests.get('URL WITH PARAMS HERE', auth=('MY USERNAME', 'MY PASSWORD'))

It is used to hit an API, but it returns the following error: "socket.error: [Errno 104] Connection reset by peer"

I am able to retrieve results using my browser. I am also able to cURL it and get results. The same problem happens when using urllib2, but for some reason pycurl seems to retrieve results.

Is there any solution to make it work or any idea as to the problem?

Your code is correct. The error might mean that the server on the other end is unhappy about what you're sending. You have to make sure you send it an appropriate request. To do that, you can:

  • Read the documentation about the host
  • Contact its owner
  • Check what your browser is sending when you successfully access your data

For the third option, use the integrated development tools on firefox, chrome, safari or your favorite browser (eg for Firefox, read this )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM