question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[🐛 Bug]: Python Proxy configuration with Proxy network

See original GitHub issue

What happened?

proxy I am using a proxy network and want to configure it with Selenium on Python. I have seen many resources use the HOST:PORT method of configuration, but proxy networks uses the “URL method” of http://USER:PASSWORD@PROXY:PORT.

See different types of configurations below:

How can we reproduce the issue?

###Selenium_Options###
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://USER:PASSWORD@PROXY:PORT")
driver = webdriver.Chrome(options=options)
driver.get("https://some_url.com")



###Desired_Capabilities###
from selenium import webdriver
from selenium.webdriver.common.proxy import *

proxy_url = "http://USER:PASSWORD@PROXY:PORT"
proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': proxy_url,
    'sslProxy': proxy_url,
    'noProxy': ''})

capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)

driver = webdriver.Chrome(desired_capabilities=capabilities)
driver.get("https://some_url.com")

Relevant log output

Log does not throw any errors with the above configurations, all the errors on on a browser side:

Reference above attached image for Selenium_Options error.

Desired Capabilities does not throw any browser errors, but the configuration still fails to add proxy.

*Proxy “URL” is in a working state and has been tested using the requests library.

FOR MORE INFORMATION: https://stackoverflow.com/questions/70806778/python-selenium-proxy-network

Operating System

Windows 10

Selenium version

Tried with: 3.141.0 and 4.0.0a7

What are the browser(s) and version(s) where you see this issue?

Version 101.0.4951.41

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 101.0.4951.41

Are you using Selenium Grid?

NA

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
lukehamil55commented, May 9, 2022

@symonk For extra context, I ran the below code using urllib.request with the proxy endpoint configuration, and the IP is correctly applied and cycled:

import urllib.request
opener = urllib.request.build_opener(
    urllib.request.ProxyHandler(
        {'http': 'http://USER:PASSWORD@PROXY:PORT/',
        'https': 'http://USER:PASSWORD@PROXY:PORT/'}))
print(opener.open('http://lumtest.com/myip.json').read())

The website http://lumtest.com/myip.json can also be used to check one’s personal IP. At this point, is it safe to rule out the validity of the proxy network endpoint, and that this problem solely lies with Selenium?

1reaction
lukehamil55commented, May 18, 2022

Opened an issue with the chromedriver project: https://bugs.chromium.org/p/chromedriver/issues/detail?id=4118 Will update this thread when I reach a solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use a Proxy with Python Requests? - ScrapingBee
To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections....
Read more >
Python Proxy Configuration Examples
This code example shows the most reliable way to use proxy authentication. But if you're using IP authentication, then you can remove USERNAME: ......
Read more >
How to solve an error that appears in conda proxy ...
The solutions are as follows: Open "Internet Options" in the Internet -> Connection -> LAN Settings -> uncheck the "Use a proxy server...
Read more >
How to Use Pip with a Proxy Server - ActiveState
Click to install and use PIP with a Proxy server for security and ... To install Python packages via a proxy server, do...
Read more >
Python Requests Module To Configure And Use Proxies - Zyte
There are multiple ways you can handle connection errors. Because sometimes the proxy that you are trying to use is just simply banned....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found