1

I need to access a website. For that I need to use proxies with authentication and a specific user-agent. Here's the code:

def start_driver(proxy_data, user_agent):
    proxy = (
            proxy_data.get('login') + ':' + proxy_data.get('password') +
            '@' + proxy_data.get('ip') + ':' + proxy_data.get('port')
    )
    executable_path = os.path.abspath(r'assets\geckodriver\driver.exe')
    firefox_binary = os.path.abspath(r'assets\firefox\browser.exe')
    firefox_options = Options()
    capabilities = webdriver.DesiredCapabilities().FIREFOX
    firefox_profile = FirefoxProfile()
    # firefox_options.add_argument('--headless')
    capabilities['pageLoadStrategy'] = 'eager'
    options = {
        'proxy': {
            'http': 'http://' + proxy,
            'https': 'https://' + proxy,
        }
    }
    driver = webdriver.Firefox(
        executable_path=executable_path,
        firefox_binary=firefox_binary,
        seleniumwire_options=options,
        capabilities=capabilities,
        firefox_profile=firefox_profile,
        firefox_options=firefox_options
    )
    driver.header_overrides = {'User-Agent': user_agent}
    return driver

To ensure everything is okay I ping http://whatsmyuseragent.org/

driver.get('http://whatsmyuseragent.org/')

And this part of the code works fine. However, when I get target website with:

driver.get('https://domain.tld/')

I get an error:

selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=nssFailure2&u=...

The curious thing about it is that when I run the script directly through PyCharm - everything works PERFECT. But after using pyinstaller with the following parameters:

pyinstaller --onefile MyScript.py

Selenium does reach http://whatsmyuseragent.org/ but can't reach targeted website https://domain.tld

I DO assume that the problem lies in pyinstaller itself but I literally CANNOT understand WHY it happens. I have only two versions to explain why it happens:

  1. Issues during compiling with pyinstaller.
  2. Targeted website somehow does not allow Selenium to reach it (but why Selenium can reach it while working out of PyCharm rather than .exe file?)

Any ideas and/or replacements to pyinstaller?

1 Answers1

0

I found the solution if someone else has this issue. Go to your python folder, and find the pyinstaller hooks folder, for me that's :

https://github.com/wkeeling/selenium-wire/issues/84#issuecomment-624389859

C:\Python37-32\Lib\site-packages\PyInstaller\hooks

Create a new file called :

hook-seleniumwire.py

Inside you need :

from PyInstaller.utils.hooks import collect_data_files

datas = collect_data_files('seleniumwire')
Suraj Rao
  • 28,186
  • 10
  • 88
  • 94