This is my code.
import requests
r = requests.get('https://academic.oup.com/journals')
then I got the error below;
ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')",))
Why I got the error? What should I do? the Request works well with other URLs like https://www.google.com
Try specifying a user-agent in the HTTP header:
❯❯❯ python3
Python 3.5.2 (default, Sep 14 2016, 11:28:32)
[GCC 6.2.1 20160901 (Red Hat 6.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> headers = requests.utils.default_headers()
>>> headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
>>> r = requests.get('https://academic.oup.com/journals', headers=headers)
>>> r
<Response [200]>
Also, make sure you follow the rules mentioned in the website's robots.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With