【问题标题】:Unable to set proxy :selenium.common.exceptions.WebDriverException:Access Denied无法设置代理:selenium.common.exceptions.WebDriverException:Access Denied
【发布时间】:2013-05-05 06:36:29
【问题描述】:

我想使用 Selenium Webdriver,但我无法这样做,因为当我运行我的代码时,我得到了以下异常。 我的代码很基础,如下。

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com.bh")
assert "Google" in driver.title
driver.close()

Exception Message
selenium.common.exceptions.WebDriverException: Message: '<HTML><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD>\n<BODY>\n<FONT face="Helvetica">\n<big><strong></strong></big><BR>\n</FONT>\n<blockquote>\n<TABLE border=0 cellPadding=1 width="80%">\n<TR><TD>\n<FONT face="Helvetica">\n<big>Access Denied (authentication_failed)</big>\n<BR>\n<BR>\n</FONT>\n</TD></TR>\n<TR><TD>\n<FONT face="Helvetica">\nYour credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.\n</FONT>\n</TD></TR>\n<TR><TD>\n<FONT face="Helvetica">\nThis is typically caused by an incorrect username and/or password, but could also be caused by network problems.\n</FONT>\n</TD></TR>\n<TR><TD>\n<FONT face="Helvetica" SIZE=2>\n<BR>\nFor assistance, contact your network support team.\n</FONT>\n</TD></TR>\n</TABLE>\n</blockquote>\n</FONT>\n</BODY></HTML>\n' 

它会打开 Firefox,但之后无法连接到 google 或任何其他本地站点。 例外是driver = webdriver.Firefox()

我在 Google 上四处搜索,并在 SO 上关注了 link

但不幸的是,我仍然遇到同样的错误。 我无法以 root 用户身份运行。我更改了代理设置并为 localhost 设置了 No Proxy 元素以及链接中提到的内容。

我使用的是 Python 2.7 并且已经安装了 selenium 2.31 版本。

我也试过设置代理。

myProxy = "*********:8080"
proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': myProxy,
    'ftpProxy': myProxy,
    'sslProxy': myProxy,
    'noProxy': 'localhost,127.0.0.1,*.abc' 
    })

driver = webdriver.Firefox(proxy=proxy)

我还尝试将代理设置为系统的代理,即在上面的代码中,'proxyType': ProxyType.SYSTEM

但它再次给出上述异常消息。 有需要设置用户名和密码的地方吗?

任何帮助将不胜感激!

【问题讨论】:

标签: selenium python-2.7 webdriver selenium-webdriver


【解决方案1】:

手动从系统上的所有浏览器中删除代理设置。我有 IE、Firefox 和 Google Chrome。 当我删除所有浏览器的代理设置并仅在 Firefox 上启用代理时,它可以正常工作而不会出现任何错误。我不知道为什么会这样工作的确切原因,可能与我不确定的 Windows 上的注册表设置有关。 完成上述操作后,我运行了基本代码,它运行良好。

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com.bh")
assert "Google" in driver.title
driver.close()

我也没有明确设置代理。默认情况下,它采用了系统的代理设置。希望这会帮助其他面临类似问题的人。

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 2011-03-28
    • 2018-03-22
    • 1970-01-01
    • 2012-01-29
    • 2018-12-06
    • 2021-10-10
    • 1970-01-01
    相关资源
    最近更新 更多