I am writing a program in Python using selenium. Everything works on the local computer, but the problem started when I tried to transfer the program to a remote server with headless mode configured. I wrote a function with driver configuration:
#necessary imports
from time import sleep
from selenium.webdriver.firefox.service import Service
from seleniumwire import webdriver
#end imports
def configure_firefox_driver_with_proxy(proxy_host=None, proxy_port=None):
print("Point 1")
options = webdriver.FirefoxOptions()
print("Point 2")
options.add_argument("--headless")
print("Point 3")
options.binary_location = '/usr/bin/firefox'
print("Point 4")
driver_path = '/root/geckodriver/geckodriver'
print("Point 5")
service = Service(driver_path)
print("Point 6")
service.log_path = '/root/[my folder]/geckodriver.log'
print("Point 7")
if not proxy_host or not proxy_port:
print("Point 8")
return webdriver.Firefox(
options=options,
service=service
)
seleniumwire_options = {
'proxy': {
'http': f'socks5://{proxy_host}:{proxy_port}',
'https': f'socks5://{proxy_host}:{proxy_port}',
'no_proxy': 'localhost,127.0.0.1',
'proxy_type': 'manual'
}
}
return webdriver.Firefox(
service=service,
options=options,
seleniumwire_options=seleniumwire_options
)
The lines options.add_argument("--headless") and service.log_path = '/root/[my folder]/geckodriver.log' were added after I uploaded it to the server. I installed Firefox and added geckodriver to the specified folder. I'm trying to run the test function:
def geckotest():
driver = configure_firefox_driver_with_proxy()
print("Point 9")
driver.get([some site])
print("Point 10")
sleep(3)
print("Point 11")
driver.quit()
But for me, when I pass 8 points normally, the program hangs for a long time here:
return webdriver.Firefox(
options=options,
service=service
)
Then I get a big error with listing files and ending
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='localhost', port=54001): Read timed out. (read timeout=120)
I can't give more details, because the log file is not created in the specified folder. Selenium version is 4.31.0, geckodriver separately starts normally, listens on port 4444. Please help fix this problem.
The problem was that I installed the snap version of firefox. I deleted this version and installed the deb version, the program worked.