简体   繁体   中英

Selenium + Python + Internet Explorer + Firm Proxy + PAC file + Credentials

I am using Selenium + Python to browse internet. Unfortunately, it does not work with Internet Explorer (but it works with Chrome) at my firm, surely because there is a proxy and the need to use a PAC file to browse internet in my firm.

Here is my code :

from selenium import webdriver
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.ie.webdriver import WebDriver as Ie


ie_path=...
url_of_the_pac_file=...

caps = DesiredCapabilities.INTERNETEXPLORER
caps["proxy"] = {"proxyType": "pac","proxyAutoconfigUrl": url_of_the_pac_file}


driver=Ie(executable_path=ie_path,capabilities=caps,port=8080)
driver.get("http://www.google.com")

Each time I run this code, I have this message :

Traceback (most recent call last):
  File "C:\Users\TEST\Desktop\demo\demo_ie.py", line 34, in <module>
    driver=Ie(executable_path=ie_path,capabilities=caps,port=8080) #, capabilities=caps, port=0, timeout=30, host=None, log_level=None, log_file=log_path, ie_options=None)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 82, in __init__
    desired_capabilities=capabilities)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: <html>
<head>
<title>Access Denied - Web Proxy</title>
<meta name="author" content="Information">
<meta name="description" content="Default exception - Web Proxy">
</head>
<body>
<center>
<font face="Arial, Helvetica, sans-serif" size="2" color="black">
<p>
<p><big><b>Access Denied (authentication_failed)</b></big>
<p>Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.
<p>If you have any questions, please contact your local support and provide information of section "Support information".
<br/>
<HR>
<p>
<TABLE border=0 cellPadding=1 style="font-family:Verdana; font-size:11px;">
<CAPTION><big><b>Support information</b></big></CAPTION>
<TR><TD>Action:</TD><TD>Default exception (authentication_failed) - Web Proxy</TD></TR>
<TR><TD>Proxy:</TD><TD>SXB9-NETpxGTW-W3</TD></TR>
<TR><TD>Client IP Address:</TD><TD>10.72.84.12</TD></TR>
<TR><TD>User-ID (realm):</TD><TD> (Domain_CDM_ProfileBasedAuth)</TD></TR>
<TR><TD>User LDAP groups:</TD><TD></TD></TR>
<TR><TD>Full URL:</TD><TD>http://127.0.0.1:8080/session</TD></TR>
<TR><TD>Method:</TD><TD>POST</TD></TR>
<TR><TD>Date:</TD><TD>2018-05-17 07:37:41</TD></TR>
<TR><TD>User agent:</TD><TD>Python http auth</TD></TR>
<TR><TD>Categories BC:</TD><TD> none</TD></TR>
<TR><TD>Categories ALL:</TD><TD> none</TD></TR>
</TABLE>
<p>
</center>
</font>
</body>
</html>

It seems it requires my credentials but I don't know how to do that. Thanks for your help!

If you are using python 2.7, you can use the following code to disable proxy setting on the browser.

urllib2.getproxies = lambda: {}
driver=Ie(executable_path=ie_path,capabilities=caps,port=8080)
driver.get("http://www.google.com")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM