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:
- Issues during compiling with
pyinstaller
. - 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
?