简体   繁体   English

Python: requests.exceptions.ConnectionError: ('Connection aborted.', OSError(“(54, 'ECONNRESET')”,))

[英]Python: requests.exceptions.ConnectionError: ('Connection aborted.', OSError(“(54, 'ECONNRESET')”,))

I don't understand why the connection aborted, I have included headers and cookies in my request.我不明白为什么连接中止,我在我的请求中包含了标题和 cookies。 Any input would be highly appreciated.任何输入将不胜感激。

import requests


url = 'https://fp.trafikverket.se/boka/#/search/SPHhISIPAfhPP/5/0/0/0'
s = requests.session()
res = s.get(url)
cookies = dict(res.cookies)
headers = dict(res.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 = s.post(url, 
    cookies=cookies, headers=headers).text

>>> requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(54, 'ECONNRESET')",))

Try the below code, it works.试试下面的代码,它可以工作。

import requests
import json

url = 'https://fp.trafikverket.se/boka/#/search/SPHhISIPAfhPP/5/0/0/0'
s = requests.session()
res = s.get(url)
cookies = dict(res.cookies)
headers = dict(res.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'
data = {}
r = s.post(url, data = json.dumps(data), cookies = cookies, headers = headers).text

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请求超时错误 (requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))) - Requests Timeout Error (requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(10060, 'WSAETIMEDOUT')"))) 如何解决 requests.exceptions.ConnectionError: ('Connection aborted.') in python web 抓取? - How to solve requests.exceptions.ConnectionError: ('Connection aborted.') in python web scraping? requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) - requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) requests.exceptions.ConnectionError :('Connection aborted。',gaierror(8,'nodename或servname提供,或未知')) - requests.exceptions.ConnectionError: ('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known')) Web 抓取 - 请求 ConnectionError: ('Connection aborted.', OSError(“(60, 'ETIMEDOUT')”,)) - Web Scraping - Requests ConnectionError: ('Connection aborted.', OSError(“(60, 'ETIMEDOUT')”,)) Python ConnectionError: ('Connection aborted.', OSError(“(10060, 'WSAETIMEDOUT')”)) - Python ConnectionError: ('Connection aborted.', OSError(“(10060, 'WSAETIMEDOUT')”)) requests.exceptions.ConnectionError Python - requests.exceptions.ConnectionError Python python - 处理连接异常(requests.exceptions.ConnectionError) - python - handle connection exception (requests.exceptions.ConnectionError) Python:requests.exceptions.ConnectionError:HTTPSConnectionPool - Python: requests.exceptions.ConnectionError: HTTPSConnectionPool 使用 python 请求获取 ('Connection aborted.', OSError(0, 'Error') 错误 - Getting ('Connection aborted.', OSError(0, 'Error') errors with python requests
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM