Python Selenium代理抛出异常

时间:2013-12-06 11:49:48

标签: python selenium

我的代码非常简单:

from selenium.webdriver.common import proxy as _px
myProxy = 'http://217.76.186.242:1080'

proxy = _px.Proxy({
    'proxyType': _px.ProxyType.MANUAL,
    'httpProxy': myProxy,
    'ftpProxy': myProxy,
    'sslProxy': myProxy,
    'noProxy': ''})

profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", choice(user_agents))
driver = webdriver.Firefox(firefox_profile=profile, proxy=proxy)
dirver.get("http://www.google.ru")

但它不起作用。它引发了一个例外:

Traceback (most recent call last):
  File "google_blog.py", line 30, in <module>
    'noProxy': ''})
  File "/home/********/.virtualenvs/helpers/local/lib/python2.7/site-packages/selenium/webdriver/common/proxy.py", line 66, in __init__
    self.proxy_type = ProxyType.load(raw['proxyType'])
  File "/home/********/.virtualenvs/helpers/local/lib/python2.7/site-packages/selenium/webdriver/common/proxy.py", line 39, in load
    raise Exception("No proxy type is found for %s" % (value))
  Exception: No proxy type is found for {'FF_VALUE': 1, 'STRING': 'MANUAL'}  

似乎一切都很好。但不是。任何提示?

1 个答案:

答案 0 :(得分:2)

我看到了问题,临时解决方法是使用

'proxyType': 'MANUAL' 

而不是

'proxyType': ProxyType.MANUAL