【问题标题】:Why doesn't my Python program reach the intended website?为什么我的 Python 程序无法访问预期的网站?
【发布时间】:2017-09-12 20:47:36
【问题描述】:

我正在尝试在 Python 3 中制作网络爬虫。我不断收到 WinError 10060 提示连接失败,因为连接方没有正确响应或连接的主机没有响应。同时使用 urllib 并尝试使用 requests 库都会产生 10060 错误。使用请求时,错误表明 URL 超出了最大重试次数。

import urllib.request

with urllib.request.urlopen('http://python.org') as response: 
    html = response.read()

人们提到这可能是代理或防火墙问题,因为我试图在我的工作网络上执行此操作。

【问题讨论】:

    标签: python-3.x web-scraping beautifulsoup urllib


    【解决方案1】:

    原来这是代理身份验证错误。只需在 get 命令中使用您的凭据添加代理即可解决此问题。

    proxies = {'http': 'http://user:pass@url:8080', 'https': 'http://user:pass@url:8080'}
    page = requests.get(webpage, proxies)
    

    【讨论】:

      猜你喜欢
      • 2022-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2018-07-05
      • 2012-12-19
      • 2013-11-30
      • 1970-01-01
      相关资源
      最近更新 更多