Firefox 无法从PyCharm/selenium在浏览器中引入任何url:http代理响应,无论设置如何

Firefox 无法从PyCharm/selenium在浏览器中引入任何url:http代理响应,无论设置如何,firefox,python-2.7,selenium-webdriver,pycharm,Firefox,Python 2.7,Selenium Webdriver,Pycharm,我在带有Firefox25的Ubuntu13.04上安装了Python 2.7.4和selenium绑定(通过“pip安装selenium”安装)。我有PyCharm社区版3.0.1,我在一个代理后面。我有一个非常简单的python测试test_selenium.py: from selenium import webdriver browser = webdriver.Firefox() browser.get("seleniumhq.org/") 当我尝试从PyCharm运行上述内容时,会

我在带有Firefox25的Ubuntu13.04上安装了Python 2.7.4和selenium绑定(通过“pip安装selenium”安装)。我有PyCharm社区版3.0.1,我在一个代理后面。我有一个非常简单的python测试test_selenium.py:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get("seleniumhq.org/")
当我尝试从PyCharm运行上述内容时,会打开Firefox浏览器,但位置栏中没有显示url。而是显示以下内容:

Traceback (most recent call last):
  File "/home/nimbula/svn/nimbula/ui-selenium-tests/test-selenium.py", line 18, in <module>
    browser = webdriver.Firefox()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 60, in __init__
    desired_capabilities=capabilities)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 71, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 113, in start_session
    'desiredCapabilities': desired_capabilities,
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 164, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 136, in check_response
    raise exception_class(value)
回溯(最近一次呼叫最后一次):
文件“/home/nimbula/svn/nimbula/ui selenium tests/test selenium.py”,第18行,在
browser=webdriver.Firefox()
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/firefox/webdriver.py”,第60行,在__
所需的能力=能力)
文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py”,第71行,在__
self.start\u会话(所需的\u功能、浏览器\u配置文件)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第113行,在启动会话中
“desiredCapabilities”:所需的功能,
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/webdriver.py”,第164行,在execute中
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python2.7/dist packages/selenium/webdriver/remote/errorhandler.py”,第136行,在check_响应中
引发异常\u类(值)
selenium.common.exceptions.WebDriverException:消息:u' 该消息是包含以下错误的html文件:

The proxy could not connect to the destination in time. Please verify the site you are attempting to access and retry.\n    </td>\n  </tr>\n</table>\n<!--/Content-->\n\n<!--Info-->\n<table class="infoTable">\n  <tr>\n    <td class="infoData">\n      <b>URL: </b><script type="text/javascript">break_line("http://127.0.0.1:51991/hub/session");</script>
代理无法及时连接到目标。请验证您试图访问的站点,然后重试。\n\n\n\n\n\n\n\n\n\n URL:中断线(“http://127.0.0.1:51991/hub/session");
因此,从上面看,SeleniumWebDriver似乎试图访问127.0.0.1:5199,但代理截获了调用。我尝试了以下代码:

from selenium import webdriver

PROXY_HOST = "<corp proxy>"
PROXY_PORT = 80

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.ftp", PROXY_HOST)
profile.set_preference("network.proxy.ftp_port", PROXY_PORT)
profile.set_preference("network.proxy.ssl", PROXY_HOST)
profile.set_preference("network.proxy.ssl_port", PROXY_PORT)
profile.set_preference("network.proxy.socks", PROXY_HOST)
profile.set_preference("network.proxy.socks_port", PROXY_PORT)
profile.set_preference("network.proxy.no_proxies_on", "127.0.0.1")
profile.update_preferences()

browser = webdriver.Firefox(firefox_profile=profile)
browser.get("seleniumhq.org/")
从selenium导入webdriver
PROXY_HOST=“”
代理_端口=80
profile=webdriver.FirefoxProfile()
profile.set_首选项(“network.proxy.type”,1)
profile.set_首选项(“network.proxy.http”,proxy_主机)
profile.set_首选项(“network.proxy.http_端口”,proxy_端口)
profile.set_首选项(“network.proxy.ftp”,proxy_主机)
profile.set_首选项(“network.proxy.ftp_端口”,proxy_端口)
profile.set_首选项(“network.proxy.ssl”,proxy_主机)
profile.set_首选项(“network.proxy.ssl_端口”,proxy_端口)
profile.set_首选项(“network.proxy.socks”,proxy_主机)
profile.set_首选项(“network.proxy.socks_port”,proxy_port)
profile.set_首选项(“network.proxy.no_proxy_on”,“127.0.0.1”)
profile.update_preferences()
browser=webdriver.Firefox(Firefox\u profile=profile)
browser.get(“seleniumhq.org/”)
仍然显示相同的错误。因为我打开了浏览器窗口,所以我检查了网络设置,它们是在python代码中指定的:127.0.0.1显示在“无代理”框中。我还尝试了以下方法:

browser = webdriver.Firefox(proxy=None)
  • 在PyCharm->Settings->Http proxy中将proxy设置为None,执行不设置代理的代码

  • 在PyCharm->Settings->Http proxy中将proxy设置为“Use proxy”,并在异常框中使用127.0.0.1指定所有必需的信息

  • 上述措施都不起作用。我还尝试从命令行执行脚本。仅当我首先执行“unset http_proxy”,然后在没有代理设置的情况下执行脚本时,它才起作用。如果我尝试使用代理设置,它将不再工作。我需要能够运行PyCharm的测试。因此,我的问题有两个方面:

  • 如何强制PyCharm不使用代理(设置->代理->无不起作用)?也许,如果我在命令行上运行“unset http_proxy”,然后从同一个命令行窗口启动PyCharm,它可能会工作。如何从命令行启动pycharm?”未找到pycharm',也未找到/bin/pycharm

  • 如何从selenium强制Firefox的代理设置为“无”


  • 感谢您的支持。

    以下是我目前的发现:

  • 强制PyCharm不使用代理:

    a。在命令行窗口(附件->终端)中取消设置代理:

    unset http_proxy
    
    b。从同一命令行窗口启动pycharm:

    <install dir>/bin/pycharm.sh
    
    启动的浏览器窗口未将代理设置为“无代理”,而是“使用系统代理设置”。如果有人知道通过python编程将Firefox代理设置为“无代理”的方法,请分享。否则,我认为这是selenium/python的一个限制

  • 我不确定SeleniumWebDriver是如何工作的,但我猜将浏览器的代理设置为“无代理”(如果可能)可能仍然无法解决上述问题。为使webdriver正常工作,可能需要取消设置系统代理。论unix的使用

    unset http_proxy
    
    在窗户上

    set proxy to none from IE (that will change the system proxy).
    

    如果有任何解释或更好的解决方案,请分享。

    我认为系统代理必须被禁用,因为如果我在Python中设置了HTTP代理和127.0.0.1作为异常(在这篇文章的中间代码),当系统代理被禁用时,它工作得很好,但是在相同的错误下失败。因此,代理截获的似乎是webdriver的内部通信,与浏览器设置无关。