wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

Error code: 502 Message: Bad Gateway. #559

Closed alimp5 closed 2 years ago

alimp5 commented 2 years ago

Greetings! at first, i would thank you @wkeeling 🥇

I read closed issues below and those didn't help me. https://github.com/wkeeling/selenium-wire/issues?q=is%3Aissue+is%3Aclosed+502

I'm using latest version of selenium-wire and undetected_chromedriver and selenium libraries by python 3.8.10 64bit. even i installed the self generated certificates by selenium-wire from itself directory. i see 502 bad gateway... error when i add proxy setting to sel-wire. proxies work fine on selenium and pure browsers.

import seleniumwire.undetected_chromedriver as uc
from seleniumwire.utils import decode as sw_decode

class ea_info (object):
    def __init__ (self):
        driver = ""
        self.my_url = "https://www.ea.com/fifa/ultimate-team/web-app/"
        self.ea_profiles = {
            "sender" :
            {
                "driver": "",
                "profile_path": r"F:\ea_env\my_captcha\chrome_sender",
                "cookie_path":  r"F:\ea_env\my_captcha\chrome_sender.pkl",
                "ea_username": "A............m",
                "ea_password": "As.......................l",
                "ea_proxy": 
                {
                    'http':  'http://nomgwfil:s0znz20wtzrv@176.116.230.128:7214',
                    'https': 'https://nomgwfil:s0znz20wtzrv@176.116.230.128:7214'
                }
            },

            "getter" :
            {.........skipped.....}
        }

        for c, item in enumerate(self.ea_profiles):
            ea_username  = self.ea_profiles[item]["ea_username"]
            ea_password  = self.ea_profiles[item]["ea_password"]
            ea_secret    = self.ea_profiles[item]["ea_secret"]

            wire_options = {
                'backend': 'mitmproxy',
                'mitmproxy_log_level': 'INFO',
                'connection_timeout': 10,
                'connection_keep_alive': False,
                'verify_ssl': False,
                'proxy': self.ea_profiles[item]["ea_proxy"]
            }
            options = uc.ChromeOptions()
            options.binary_location = r'C:\Program Files\Google\Chrome\Application\chrome.exe'    ## google chrome 64 bit.
            options.user_data_dir = profile_path
            options.add_argument('--user-data-dir={}'.format(profile_path))
            options.add_argument('--ignore-ssl-errors')
            options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
            options.add_argument('--excludeSwitches --enable-logging')
            driver = uc.Chrome (executable_path=r"F:\ea_snipe\ea_games\chromedriver_ver102.exe",  options=options,  seleniumwire_options=wire_options)
            self.ea_profiles[item]["driver"] = driver
            sleep(1)
            driver.set_window_position(0, 0)
            driver.set_window_size(1143, 1000)
            driver.implicitly_wait(100)
            driver.set_page_load_timeout(100)

            driver.get (self.my_url)

Errors:

Traceback (most recent call last):
  File "f:/ea_snipe/ea_games/fast_snipe_mvp.py", line 241, in <module>
    ea_info()
  File "f:/ea_snipe/ea_games/fast_snipe_mvp.py", line 104, in __init__
    driver = uc.Chrome (executable_path=r"F:\ea_snipe\ea_games\chromedriver_ver102.exe",  options=options,  seleniumwire_options=wire_options)
  File "F:\ea_snipe\lib\site-packages\seleniumwire\undetected_chromedriver\webdriver.py", line 61, in __init__
    super().__init__(*args, **kwargs)
  File "F:\ea_snipe\lib\site-packages\undetected_chromedriver\__init__.py", line 233, in __init__
    patcher.auto()
  File "F:\ea_snipe\lib\site-packages\undetected_chromedriver\patcher.py", line 127, in auto
    release = self.fetch_release_number()
  File "F:\ea_snipe\lib\site-packages\undetected_chromedriver\patcher.py", line 148, in fetch_release_number
    return LooseVersion(urlopen(self.url_repo + path).read().decode())
  File "C:\Python38\lib\urllib\request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python38\lib\urllib\request.py", line 531, in open
    response = meth(req, response)
  File "C:\Python38\lib\urllib\request.py", line 640, in http_response
    response = self.parent.error(
  File "C:\Python38\lib\urllib\request.py", line 569, in error
    return self._call_chain(*args)
  File "C:\Python38\lib\urllib\request.py", line 502, in _call_chain
    result = func(*args)
  File "C:\Python38\lib\urllib\request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 502: Bad Gateway
alimp5 commented 2 years ago

An interesting thing happened, i removed the seleniumwire_options and i got the same error.

before:

driver = uc.Chrome (executable_path=r"F:\ea_snipe\ea_games\chromedriver_ver102.exe", options=options, seleniumwire_options=wire_options)

after:

driver = uc.Chrome (executable_path=r"F:\ea_snipe\ea_games\chromedriver_ver102.exe", options=options)

where is the problem !?

alimp5 commented 2 years ago

An interesting thing happened, :DDDDD i'm sure the entered setting in selenium-wire module is not passed to undetected_chromedriver module. many of Microsoft's services are not available in IRAN country, because of U.S sanctions. when i turned vpn on, then the script worked without any problem/error.

buttttt, when i configure the undetected_chromedriver manually (set chrome driver executable path and other options), it work without seeing any error like 401 or 403 forbidden access. if your module send the configured settings for UC, i think the problem is solved.

sorry for my EN language =)

johny322 commented 2 years ago

@alimp5 hi Did you solve this problem? I have the similar

wkeeling commented 2 years ago

Sorry for the delay in responding.

So are you saying that the problem happens when you use seleniumwire.undetected_chromedriver and pass a proxy server in seleniumwire_options?

johny322 commented 2 years ago

@wkeeling Hello. Thank you for your answer. I have already solved this problem. The problem was in incorrect proxies