Skip to content

Chrome is stuck with same IP when using a proxy. #2617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mobti100 opened this issue Mar 17, 2024 · 7 comments
Closed

Chrome is stuck with same IP when using a proxy. #2617

mobti100 opened this issue Mar 17, 2024 · 7 comments
Labels
duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@mobti100
Copy link

mobti100 commented Mar 17, 2024

Proxy and IP info from the session:
user:[email protected]:12323
{'ip': '5.178.6.85', 'city': 'Lizy-sur-Ourcq', 'region': 'Île-de-France', 'country': 'FR', 'loc': '49.0245,3.0218', 'org': 'AS2914 NTT America, Inc.', 'postal': '77440', 'timezone': 'Europe/Paris', 'readme': 'https://ipinfo.io/missingauth'}

Proxy and IP info from chrome:
user:[email protected]:12323
{
  "ip": "185.134.195.244",
  "city": "Saint-Denis",
  "region": "Île-de-France",
  "country": "FR",
  "loc": "48.9356,2.3539",
  "org": "AS6830 Liberty Global B.V.",
  "postal": "93200",
  "timezone": "Europe/Paris",
  "readme": "https://ipinfo.io/missingauth"
}

It does not change even when changing proxy providers, it's just stuck with that data.

async def sign_in(username, password, proxy):
    try:
        with SB(uc=True, proxy=proxy) as sb:
            print(proxy)
            sb.driver.uc_open('http://example.com')
            sb.driver.type('#username', username)
            sb.driver.type('#password', password)
            sb.driver.click('#kc-login')
            standard_logger.info(f'Signed in as {username}')
            return sb.driver.get_cookies()
    except Exception:
        raise


async def create_session(account, proxy, timeout):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36'}
    session = AsyncSession(
        impersonate='chrome119',
        timeout=timeout,
        headers=headers,
        proxies={'https': proxy}
    )
    response = await session.get('https://ipinfo.io/json')
    print(proxy)
    print(response.json())
    cookies = await sign_in(account['username'], account['password'], proxy)
    for cookie in cookies:
            session.cookies.set(cookie['name'], cookie['value'], domain=cookie['domain'])
    return session, account['username'], account['issuer'], account['id'], account['variant']
@mobti100
Copy link
Author

Screenshot 2024-03-17 at 02 57 00

I also noticed that the driver uses one single proxy for all instances even though each driver is configured to use a different proxy

@mdmintz mdmintz added duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Mar 17, 2024
@mdmintz
Copy link
Member

mdmintz commented Mar 17, 2024

You have to set multi_proxy=True:

multi_proxy=False, # Allow multiple proxies with auth when multi-threaded.

This feature has existed since April 2023 - #1832

Duplicate of #2101 (comment)

@mdmintz mdmintz closed this as completed Mar 17, 2024
@mobti100
Copy link
Author

Yes, I just fixed it and you replied. Also sometimes the challenge page doesn't let me through and I have to manually click verify, any fix for that.

@mdmintz
Copy link
Member

mdmintz commented Mar 17, 2024

Set a longer reconnect_time for sb.driver.uc_open_with_reconnect(url, reconnect_time).
Has to be at least as long as the time it takes for the page to finish loading. Eg. examples/raw_pixelscan.py

@mobti100
Copy link
Author

I appreciate your help

@mobti100
Copy link
Author

I noticed when launching multiple instances asynchronously, a conflict occurs in how proxy_ext_dir_n folders are created.
I keep receiving for example proxy_ext_dir_2 already exists because all instances are attempting to create extension folders at the same time. Is there a way that I can custom rename those folder in SB so such conflict does not happen?

def get_cookies(proxy, username, password):
    with SB(uc=True, proxy=proxy, multi_proxy=True) as sb:
        sb.driver.uc_open_with_reconnect('http://example.com/login', 5)
        sb.driver.type('#username', username)
        sb.driver.type('#password', password)
        sb.driver.click('#login')

        return sb.driver.get_cookies()

async def create_session(account, proxy, timeout):
    headers = {
        'User-Agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) '
                       'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 '
                       'Safari/537.36')
    }
    session = AsyncSession(
        impersonate='chrome119',
        timeout=timeout,
        http_version=CurlHttpVersion.V2_0,
        headers=headers,
        proxies={'https': proxy}
    )

    loop = asyncio.get_running_loop()
    cookies = await loop.run_in_executor(custom_executor, get_cookies, proxy, account['username'], account['password'])
    for cookie in cookies:
        session.cookies.set(cookie['name'], cookie['value'], domain=cookie['domain'])

    return session, account['username'], account['issuer'], account['id'], account['variant']

@mdmintz
Copy link
Member

mdmintz commented Mar 17, 2024

Multithreaded UC Mode: #2006 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate The answer/solution already exists somewhere invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants