【问题标题】:Python-requests [('Connection aborted.', TimeoutError(10060) ]Python-requests [('Connection aborted.', TimeoutError(10060) ]
【发布时间】: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)

这可能与网站的安全性有关吗?我想找到一种解决方法

【问题讨论】:

标签: python python-requests


【解决方案1】:

由于声誉低,我无法发表评论,因此发布作为答案, 我想你会在下面的链接中找到你的答案:

Python3 error

【讨论】:

  • 我试过了,没用。现在它给了我这个消息 [HTTPSConnectionPool(host='the website', port=443): Read timed out。 (读取超时=5)]
【解决方案2】:

我使用 selenium 和用户代理选项,我能够访问该网站

user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36' options.add_argument('user-agent={0}'.format(user_agent))

非常感谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 2020-11-04
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多