gpt4 book ai didi

Python3 连接被对等方重置

转载 作者:太空宇宙 更新时间:2023-11-03 15:51:27 25 4
gpt4 key购买 nike

urllib.error.URLError urlopen error [Errno 54] Connection reset by peer

当尝试获取 notino.com 时,我收到此错误。我猜这家伙用了一些聪明的方法来防止屏幕scraper。我尝试添加 header 和 cookie,但这不起作用

from urllib.request import urlopen
url = "https://www.notino.com"
html = urlopen(url)

最佳答案

自动机器人检测机制很可能会断开您的连接。您应该提供一个 User-Agent header 来伪造浏览器访问 - 对我有用:

>>> import requests
>>> response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'})
>>> response.status_code
200

使用requests module在这个例子中。

关于Python3 连接被对等方重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41255134/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com