Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does it Support socks5://IP_ADDRESS:PORT@USER:PASS"? #3118

Answered by mdmintz
STARKILLER-1 asked this question in Q&A
Discussion options

Does it Support socks5://IP_ADDRESS:PORT@USER:PASS"?

You must be logged in to vote

Chromium doesn't support SOCKS5 authenticated proxies (https://issues.chromium.org/issues/40829748).

For socks4 or socks5 proxies, use these formats for the proxy_string:

Unauthenticated:

  • socks4://IP_ADDRESS:PORT

  • socks5://IP_ADDRESS:PORT

Authenticated:

  • socks4://USER:PASS@IP_ADDRESS:PORT

If you're using Wire Mode (which DOES NOT support UC Mode), there's a possible workaround:

from seleniumbase import Driver
def set_proxy():
 driver.proxy = {
 "http": "socks5://user:pass@ip:port",
 "https": "socks5://user:pass@ip:port",
 "no_proxy": "localhost,127.0.0.1",
 }
driver = Driver(wire=True)
try:
 set_proxy()
 driver.get("https://ipinfo.io/")
 driver.s...

Replies: 3 comments 5 replies

Comment options

Chromium doesn't support SOCKS5 authenticated proxies (https://issues.chromium.org/issues/40829748).

For socks4 or socks5 proxies, use these formats for the proxy_string:

Unauthenticated:

  • socks4://IP_ADDRESS:PORT

  • socks5://IP_ADDRESS:PORT

Authenticated:

  • socks4://USER:PASS@IP_ADDRESS:PORT

If you're using Wire Mode (which DOES NOT support UC Mode), there's a possible workaround:

from seleniumbase import Driver
def set_proxy():
 driver.proxy = {
 "http": "socks5://user:pass@ip:port",
 "https": "socks5://user:pass@ip:port",
 "no_proxy": "localhost,127.0.0.1",
 }
driver = Driver(wire=True)
try:
 set_proxy()
 driver.get("https://ipinfo.io/")
 driver.sleep(5)
finally:
 driver.quit()

That works because selenium-wire sets up the proxy outside the browser on a locally-running server.

(Again, Wire Mode does not support UC Mode. Use wire=True to activate it.)

You must be logged in to vote
1 reply
Comment options

Thank you very much!

Answer selected by mdmintz
Comment options

hi, i tried this way as the codes(examples/cdp_mode/raw_proxy.py) below, but return error by both proxy format, so what should i do?

thanks.

from seleniumbase import decorators
from seleniumbase import sb_cdp
# Change this to "ip:port" or "user:pass@ip:port"
proxy = None
# proxy = 'socks5://127.0.0.1:10080'
proxy = '127.0.0.1:10080'
@decorators.print_runtime("CDP Proxy Example")
def main():
 url = "https://api.ipify.org/"
 sb = sb_cdp.Chrome(url, lang="en", pls="none", proxy=proxy)
 ip_address = sb.get_text("body")
 if "ERR" in ip_address:
 raise Exception("Failed to determine IP Address!")
 print("\n\nMy IP Address = %s\n" % ip_address)
 sb.open("https://ipinfo.io/%s" % ip_address)
 sb.sleep(2)
 sb.wait_for_text(ip_address, "h1", timeout=20)
 sb.find_element('[href="/signup"]')
 sb.wait_for_text("Hosted domains", timeout=20)
 sb.highlight("h1")
 pop_up = '[role="dialog"] span.cursor-pointer'
 sb.click_if_visible(pop_up)
 sb.highlight("#block-summary")
 sb.click_if_visible(pop_up)
 sb.highlight("#block-geolocation")
 sb.click_if_visible(pop_up)
 sb.sleep(2)
 print("Displaying Host Info:")
 text = sb.get_text("#block-summary").split("Hosted domains")[0]
 rows = text.split("\n")
 data = []
 for row in rows:
 if row.strip() != "":
 data.append(row.strip())
 print("\n".join(data).replace('\n"', ' "'))
 print("\nDisplaying GeoLocation Info:")
 text = sb.get_text("#block-geolocation")
 text = text.split("IP Geolocation data")[0]
 rows = text.split("\n")
 data = []
 for row in rows:
 if row.strip() != "":
 data.append(row.strip())
 print("\n".join(data).replace('\n"', ' "'))
 sb.sleep(3)
 sb.driver.stop()
if __name__ == "__main__":
 main()

and the error messages are :


C:\Users\Administrator\PycharmProjects\SeleniumBase-master\venv\Scripts\python.exe C:/Users/Administrator/PycharmProjects/SeleniumBase-master/examples/cdp_mode/raw_proxy.py
<info> - {CDP Proxy Example} ran for 3.21 seconds.
Traceback (most recent call last):
 File "C:\Users\Administrator\PycharmProjects\SeleniumBase-master\examples\cdp_mode\raw_proxy.py", line 53, in <module>
 main()
 File "C:\ProgramData\anaconda3\Lib\contextlib.py", line 81, in inner
 return func(*args, **kwds)
 ^^^^^^^^^^^^^^^^^^^
 File "C:\Users\Administrator\PycharmProjects\SeleniumBase-master\examples\cdp_mode\raw_proxy.py", line 16, in main
 raise Exception("Failed to determine IP Address!")
Exception: Failed to determine IP Address!
Process finished with exit code -1073741819 (0xC0000005)
You must be logged in to vote
4 replies
Comment options

Use the SB() format for SOCKS5 without auth. (Not the sb_cdp format)

Comment options

thanks for reply. and i tried the way as below, but it does not work as well, it says no internet connection though the local socks5 is working.

could you please help me ?

Thanks.


from seleniumbase import SB
# proxy = 'socks5://127.0.0.1:10080'
proxy = '127.0.0.1:10080'
with SB(uc=True, test=True, locale="en", proxy=proxy) as sb:
 url = "https://gitlab.com/users/sign_in"
 sb.activate_cdp_mode(url)
 sb.sleep(10)
 sb.uc_gui_click_captcha()
 sb.sleep(200)
Comment options

You commented out the line that you need. The proxy string should begin with "socks5" if it's a SOCKS5 proxy.
But make sure it's not an authenticated SOCKS5 proxy, because then it won't work.
And if it still doesn't work, then there may be an issue with your proxy.

Comment options

thanks. i tried both, but neither of them worked...

and the local socks5 proxy 10080 works perfect with selenium + chrome, so anyway i need to check out why the proxy does not work with seleniumbase

proxy = 'socks5://127.0.0.1:10080'
proxy = '127.0.0.1:10080'
Comment options

the local proxy proxy='socks5://127.0.0.1:10080' is what i created to work around the socks5 with authentication. it works fine with selenium chrome with codes as below,

opts.add_argument(f"--proxy-server={proxy}")

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /