【问题标题】:IOError: [Errno url error] invalid proxy for http: 'xxx.xxx.xxx.xxx'IOError: [Errno url 错误] http: 'xxx.xxx.xxx.xxx' 的代理无效
【发布时间】:2011-03-12 14:23:23
【问题描述】:

我的脚本有问题。 它应该通过代理打开一个网站,但我总是遇到这个错误,我正在尝试使用几个代理...

会是什么?

Traceback (most recent call last):
  File "C:\Users\Shady\Desktop\ptzplace.3.0 - Copy.py", line 43, in <module>
    h = urllib.urlopen(website, proxies = {'http': proxy})
  File "C:\Python26\lib\urllib.py", line 86, in urlopen
    return opener.open(url)
  File "C:\Python26\lib\urllib.py", line 200, in open
    return self.open_unknown_proxy(proxy, fullurl, data)
  File "C:\Python26\lib\urllib.py", line 219, in open_unknown_proxy
    raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
IOError: [Errno url error] invalid proxy for http: 'xxx.xxx.xxx.xxx'

脚本是这样的

proxylist = ['79.174.195.84:80',
             '79.174.195.82:80',
             '80.233.184.227:8080',
             '79.174.195.80:80',
             '80.233.184.226:8080',
             '79.174.33.95:3128']
for proxy in proxylist:
            h = urllib.urlopen(website, proxies = {'http': proxy})

【问题讨论】:

    标签: python windows proxy


    【解决方案1】:

    尝试urllib2.urlopen 而不是urllib.urlopen。我遇到过urllib.urlopen 在我的代理服务器上阻塞但urllib2.urlopen 可以正常打开它的情况。

    【讨论】:

    • 哦..这个对我有用,但我不知道为什么。就像我的余生一样:D
    【解决方案2】:

    我相信您在每个代理之前都需要 http 架构标识符:

    proxylist = ['http://79.174.195.84:80',... 'http://79.174.33.95:3128'] 
    

    【讨论】:

      【解决方案3】:

      我用你的代理列表尝试下一个代码,但花了很长时间,所以我得到了其他代理:P

      import urllib
      website = 'http://www.google.com/'
      proxylist = ('http://75.101.215.123:9090', 'http://94.198.47.6:3128')
      connlist = (urllib.urlopen(website, proxies = {'http': proxy}) for proxy in proxylist)
      for conn in connlist:
          print conn.read()
          conn.close()
      

      【讨论】:

      • hmmm...显然,您的作品...我会尝试使用您的基础修改我的...
      • 很奇怪......你在我的脚本中的代码也不起作用......真是个地狱
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 2014-12-11
      • 1970-01-01
      • 2015-07-29
      • 2023-03-15
      相关资源
      最近更新 更多