Python 使用代理在Firefox中配置Selenium

Python 使用代理在Firefox中配置Selenium,python,selenium,proxy,Python,Selenium,Proxy,我正在尝试使用Python在Selenium中测试一个示例。我正在使用代理服务器连接到具有身份验证的Internet。当我尝试运行以下代码时: 从selenium导入webdriver 如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu': proxy=“some\u IP” 端口=3128 fp=webdriver.FirefoxProfile() fp.set_首选项('network.proxy.ssl_port',int(port)) fp.set_首选项

我正在尝试使用Python在Selenium中测试一个示例。我正在使用代理服务器连接到具有身份验证的Internet。当我尝试运行以下代码时:

从selenium导入webdriver
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
proxy=“some\u IP”
端口=3128
fp=webdriver.FirefoxProfile()
fp.set_首选项('network.proxy.ssl_port',int(port))
fp.set_首选项('network.proxy.ssl',proxy)
fp.set_首选项('network.proxy.http_port',int(port))
fp.set_首选项('network.proxy.http',proxy)
fp.set_首选项('network.proxy.ftp',proxy)
fp.set_首选项('network.proxy.ftp_port',int(port))
fp.set_首选项('network.proxy.socks',proxy)
fp.set_首选项('network.proxy.socks_port',int(port))
fp.set_首选项('network.proxy.type',1)
浏览器=webdriver.Firefox(Firefox\u profile=fp)
浏览器。设置页面加载超时(15)
browser.get('http://www.google.com')
打印浏览器.title
Firefox浏览器打开时没有任何问题,在其代理配置中一切正常,甚至打开了验证弹出窗口。如果我对自己进行身份验证,我可以毫无问题地导航。问题是,在这背后,我得到了以下错误:

Traceback (most recent call last):
  File "D:/_Vkt0r/iStuffs/Jobs/Projects/test-proxy/test.py", line 25, in <module>
        browser = webdriver.Firefox(firefox_profile=fp)
  File "D:\_Vkt0r\iStuffs\Jobs\Projects\test-proxy\selenium\webdriver\firefox
        \webdriver.py", line 62, in __init__ desired_capabilities=capabilities)     
  File "D:\_Vkt0r\iStuffs\Jobs\Projects\test-proxy\selenium\webdriver\remote
        \webdriver.py", line 72, in __init__ self.start_session(desired_capabilities, 
        browser_profile)      
  File "D:\_Vkt0r\iStuffs\Jobs\Projects\test-proxy\selenium\webdriver\remote
        \webdriver.py", line 114, in start_session 'desiredCapabilities': 
        desired_capabilities,            
  File "D:\_Vkt0r\iStuffs\Jobs\Projects\test-proxy\selenium\webdriver\remote
        \webdriver.py", line 165, in execute
         self.error_handler.check_response(response)
  File "D:\_Vkt0r\iStuffs\Jobs\Projects\test-proxy\selenium\webdriver\remote
        \errorhandler.py", line 136, in check_response raise exception_class(value)
  selenium.common.exceptions.WebDriverException: Message: '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>ERROR: Acceso Denegado a la Cach\xc3\xa9</title> <style type="text/css"><!--  /*\n Stylesheet for Squid Error pages\n Adapted from design by Free CSS Templates\n http://www.freecsstemplates.org\n Released for free under a Creative Commons Attribution 2.5 License\n*/\n\n/* Page basics */\n* {\n\tfont-family: verdana, sans-serif;\n}\n\nhtml body {\n\tmargin: 0;\n\tpadding: 0;\n\tbackground: #efefef;\n\tfont-size: 12px;\n\tcolor: #1e1e1e;\n}\n\n/* Page displayed title area */\n#titles {\n\tmargin-left: 15px;\n\tpadding: 10px;\n\tpadding-left: 100px;\n\tbackground: url(\'http://www.squid-cache.org/Artwork/SN.png\') no-repeat left;\n}\n\n/* initial title */\n#titles h1 {\n\tcolor: #000000;\n}\n#titles h2 {\n\tcolor: #000000;\n}\n\n/* special event: FTP success page titles */\n#titles ftpsuccess {\n\tbackground-color:#00ff00;\n\twidth:100%;\n}\n\n/* Page displayed body content area */\n#content {\n\tpadding: 10px;\n\tbackground: #ffffff;\n}\n\n/* General text */\np {\n}\n\n/* error brief description */\n#error p {\n}\n\n/* some data which may have caused the problem */\n#data {\n}\n\n/* the error message received from the system or other software */\n#sysmsg {\n}\n\npre {\n    font-family:sans-serif;\n}\n\n/* special event: FTP / Gopher directory listing */\n#dirmsg {\n    font-family: courier;\n    color: black;\n    font-size: 10pt;\n}\n#dirlisting {\n    margin-left: 2%;\n    margin-right: 2%;\n}\n#dirlisting tr.entry td.icon,td.filename,td.size,td.date {\n    border-bottom: groove;\n}\n#dirlisting td.size {\n    width: 50px;\n    text-align: right;\n    padding-right: 5px;\n}\n\n/* horizontal lines */\nhr {\n\tmargin: 0;\n}\n\n/* page displayed footer area */\n#footer {\n\tfont-size: 9px;\n\tpadding-left: 10px;\n}\n  body :lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; } :lang(he) { direction: rtl; }  --></style> </head><body id=ERR_CACHE_ACCESS_DENIED> <div id="titles"> <h1>ERROR</h1> <h2>Cache Acceso Denegado</h2> </div> <hr>  <div id="content"> <p>Se encontr\xc3\xb3 el siguiente error al intentar recuperar la direcci\xc3\xb3n URL: <a href="http://127.0.0.1:12233/hub/session">http://127.0.0.1:12233/hub/session</a></p>  <blockquote id="error"> <p><b>Acceso Denegado a la Cach\xc3\xa9</b></p> </blockquote>  <p>Lo lamento, tu no est\xc3\xa1s autorizado a solicitar http://127.0.0.1:12233/hub/session de este cach\xc3\xa9 hasta que te hayas autenticado.</p>  <p>Please contact the <a href="mailto:webmaster?subject=CacheErrorInfo%20-%20ERR_CACHE_ACCESS_DENIED&body=CacheHost%3A%20squid.proxy%0D%0AErrPage%3A%20ERR_CACHE_ACCESS_DENIED%0D%0AErr%3A%20%5Bnone%5D%0D%0ATimeStamp%3A%20Tue,%2005%20Nov%202013%2019%3A44%3A22%20GMT%0D%0A%0D%0AClientIP%3A%20192.168.10.33%0D%0A%0D%0AHTTP%20Request%3A%0D%0APOST%20%2Fhub%2Fsession%20HTTP%2F1.1%0AAccept-Encoding%3A%20identity%0D%0AContent-Length%3A%20131%0D%0AHost%3A%20127.0.0.1%3A12233%0D%0AAccept%3A%20application%2Fjson%0D%0AUser-Agent%3A%20Python-urllib%2F2.7%0D%0AConnection%3A%20close%0D%0AContent-Type%3A%20application%2Fjson%3Bcharset%3DUTF-8%0D%0A%0D%0A%0D%0A">cache administrator</a> if you have difficulties authenticating yourself.</p>  <br> </div>  <hr>  <div id="footer"> <p>Generado Tue, 05 Nov 2013 19:44:22 GMT por squid.proxy (squid/3.1.19)</p> <!-- ERR_CACHE_ACCESS_DENIED --> </div> </body></html> ' 
回溯(最近一次呼叫最后一次):
文件“D://_Vkt0r/iStuffs/Jobs/Projects/test proxy/test.py”,第25行,在
浏览器=webdriver.Firefox(Firefox\u profile=fp)
文件“D:\\u Vkt0r\iStuffs\Jobs\Projects\test proxy\selenium\webdriver\firefox
\webdriver.py“,第62行,在_uinit__uu所需的能力=能力中)
文件“D:\\u Vkt0r\iStuffs\Jobs\Projects\test proxy\selenium\webdriver\remote
\webdriver.py”,第72行,在_uinit__;self.start_u会话中(所需的_u功能,
浏览器(用户配置文件)
文件“D:\\u Vkt0r\iStuffs\Jobs\Projects\test proxy\selenium\webdriver\remote
\webdriver.py”,第114行,在启动会话“desiredCapabilities”中:
所需的作战能力,
文件“D:\\u Vkt0r\iStuffs\Jobs\Projects\test proxy\selenium\webdriver\remote
\webdriver.py”,执行中的第165行
self.error\u handler.check\u响应(响应)
文件“D:\\u Vkt0r\iStuffs\Jobs\Projects\test proxy\selenium\webdriver\remote
\errorhandler.py”,检查响应引发异常类(值)中的第136行
selenium.common.exceptions.WebDriverException:Message:'错误:Acceso Denegado a la Cach\xc3\xa9错误缓存Acceso Denegado
Se Encentr\xc3\xb3 el siguiente ERROR al INTERROR al INTERNAL RECUPER la direcci\xc3\xb3n URL:

Acceso Denegado a la Cach\xc3\xa9

,tu没有est\xc3\xa1s自动编辑请求http://127.0.0.1:12233/hub/session de este cach\xc3\xa9 hasta que te hayas autenticado。

如果您在认证自己时遇到困难,请联系。



Generado Tue,2013年11月5日19:44:22 GMT por squid.proxy(squid/3.1.19)

'

我正在使用selenium 2.34和Firefox 17。非常感谢您的帮助。

4天后,我终于找到了这个问题的解决方案。问题在于浏览器排除,我指的是任何浏览器中代理配置中的选项卡。您需要在排除项中的任何浏览器中输入以下两个地址:

localhost和127.0.0.1


这一点非常重要,因为如果一个人留下这个问题,就会导致Selenium出现问题,因为它会尝试连接到上面提到的两个地址。

在找到解决此问题的方法4天后,我终于找到了它。问题在于浏览器排除,我指的是任何浏览器中代理配置中的选项卡。您需要在排除项中的任何浏览器中输入以下两个地址:

localhost和127.0.0.1


这一点非常重要,因为如果一个人留下这个问题,就会导致Selenium出现问题,因为它会尝试连接到上面提到的两个地址。

在找到解决此问题的方法4天后,我终于找到了它。问题在于浏览器排除,我指的是任何浏览器中代理配置中的选项卡。您需要在排除项中的任何浏览器中输入以下两个地址:

localhost和127.0.0.1


这一点非常重要,因为如果一个人留下这个问题,就会导致Selenium出现问题,因为它会尝试连接到上面提到的两个地址。

在找到解决此问题的方法4天后,我终于找到了它。问题在于浏览器排除,我指的是任何浏览器中代理配置中的选项卡。您需要在排除项中的任何浏览器中输入以下两个地址:

localhost和127.0.0.1


这一点非常重要,因为如果一个人留下这个地址,就会导致Selenium出现问题,因为它试图连接到上面提到的两个地址。

您能解释更多吗?不太理解。如何在python脚本中添加这两个排除项?您能解释更多吗?不太理解。如何在python脚本中添加这两个排除项?您能解释更多吗?不太理解。如何在python脚本中添加这两个排除项?您能解释更多吗?不太理解。如何在python脚本中添加这两个排除?