【发布时间】:2020-09-23 00:59:45
【问题描述】:
我正在使用带有 requests 2.23.0 库的 Python 3.7 并尝试抓取网站,但收到以下错误消息:
('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None))
我使用了agent但没有运气,我也尝试指定timeout,仍然面临同样的问题。
当我通过浏览器访问该网站时,它运行良好
我在其他一些网站上使用了相同的代码,效果很好。
非常感谢任何形式的帮助。
-我能够捕捉到异常,但我想避免它并实际访问网站
这是代码(就像尝试访问网站一样简单):
from requests import get
try:
agent = {'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
url = "the url I'm trying to access"
html = get(url, headers = agent)
except (Exception) as error :
print ("Error", error)
这可能与网站的安全性有关吗?我想找到一种解决方法
【问题讨论】:
-
这能回答你的问题吗? Checking for Timeout Error in python