windows IOError: [Errno url error] http: 'xxx.xxx.xxx.xxx' 的代理无效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3191254/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:46:59  来源:igfitidea点击:

IOError: [Errno url error] invalid proxy for http: 'xxx.xxx.xxx.xxx'

pythonwindowsproxy

提问by Bruno 'Shady'

I'm having some trouble with my script. It's supposed to open a website trough a proxy but I get, always, this error, with several proxies that I'm trying to...

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

What could it be?

会是什么呢?

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'

The script is this

剧本是这样的

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})

回答by shroud

Try urllib2.urlopeninstead of urllib.urlopen. I've had situations where urllib.urlopenchokes on my proxy server but urllib2.urlopenopens it fine.

尝试urllib2.urlopen代替urllib.urlopen. 我遇到过urllib.urlopen代理服务器阻塞但urllib2.urlopen打开正常的情况。

回答by chryss

I believe you need the http schema identifier before each proxy:

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

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

回答by razpeitia

I try the next code with your proxylist but it tooks so long, so I got other proxies :P

我用你的代理列表尝试下一个代码,但它花了很长时间,所以我得到了其他代理: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()