Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium代理引发异常_Python_Selenium - Fatal编程技术网

Python Selenium代理引发异常

Python Selenium代理引发异常,python,selenium,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, 'noProx

我有一段非常简单的代码:

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'}  
回溯(最近一次呼叫最后一次):
文件“google_blog.py”,第30行,在
'noProxy':''})
文件“/home/*********/.virtualenvs/helpers/local/lib/python2.7/site packages/selenium/webdriver/common/proxy.py”,第66行,在__
self.proxy_type=ProxyType.load(原始['ProxyType'])
加载文件“/home/*********/.virtualenvs/helpers/local/lib/python2.7/site packages/selenium/webdriver/common/proxy.py”,第39行
引发异常(“未找到%s”%(值)的代理类型”)
异常:找不到{'FF_VALUE':1,'STRING':'MANUAL'}的代理类型

看起来一切都很好。但是没有。有什么提示吗?

我明白了问题所在,暂时的解决办法是使用

'proxyType': 'MANUAL' 
而不是

'proxyType': ProxyType.MANUAL

干得好!但是为什么呢?我曾经试着在文档中这样做,但是没有成功…现在一切都好了。Thanks@oleg.foreigner新版本似乎有缺陷。它适用于旧版本。:)