最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python 3.x - get ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connecti

programmeradmin2浏览0评论

I tried to web scrape a job board (;type=standout&origin=jobTitle#sol=1cd5168c3d3c5734f0b9bd12b20c50b50488188e) and everything are fine when I tested it on Postman

However, I copied the code and all the headers from Postman but I got this error when I ran the test on python script: "requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))"

I've tried multiple solution on stackoverflow but none of them works for my case. E.g.set the User-Agent, specific Content-Type, set the connection to 'close' etc

import requests

url = ";type=standout&origin=jobTitle"

payload = {}
headers = {
'Content-Type': 'text/html; charset=utf-8',
'Transfer-Encoding': 'chunked',
'Connection': 'keep-alive',
'CF-Ray': 'example1-HKG',
'CF-Cache-Status': 'DYNAMIC',
'Cache-Control': 'no-cache',
'accept-language':'zh-HK,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6,ja;q=0.5',
'Expires': '0',
'Strict-Transport-Security': 'max-age=157680000',
'Vary': 'Accept-Encoding',
'Pragma': 'no-cache',
'seek-melways': 'true',
'x-envoy-upstream-service-time': '330',
'x-request-id': 'example2',
'Server': 'cloudflare',
'Content-Encoding': 'gzip',
'Cookie': 'example3',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
}

response = requests.request("GET", url, headers=headers, data=payload)

print(response.text)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论