0

I'm trying to run a simple python script that open firefox and search some info on https://biblioteca.aneel.gov.br/.

On my computer the script works, but when i try to run on heroku, it always crashes. I tried all tutorials that I could find, but I don't know what more to do.

I did:

  1. I put as 'Buildpacks' on heroku: https://github.com/pyronlaboratory/heroku-integrated-firefox-geckodriver
  2. In 'Config Vars' on heroku:
    • FIREFOX_BIN = /app/vendor/firefox/firefox
    • GECKODRIVER_PATH = /app/vendor/geckodriver/geckodriver
    • LD_LIBRARY_PATH = /usr/local/lib:/usr/lib:/lib:/app/vendor
    • PATH = /usr/local/bin:/usr/bin:/bin:/app/vendor/
  3. Adjuste code on heroku:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from bs4 import BeautifulSoup
import re
import yagmail
import time
import os

options = webdriver.FirefoxOptions()
# enable trace level for debugging 
options.log.level = "trace"
options.add_argument("-remote-debugging-port=9224")
options.add_argument("-headless")
options.add_argument("-disable-gpu")
options.add_argument("-no-sandbox")
binary = FirefoxBinary(os.environ.get('FIREFOX_BIN'))

rea_inicial='teste'
while True:
    driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
    #driver.maximize_window()
    driver.get("https://biblioteca.aneel.gov.br/Busca/Avancada")
    print('entrando no site...')
    #time.sleep(5)

    # Busca por legislacoo
    driver.find_element(By.XPATH, '/html/body/main/div/div/div[2]/div/div/button[2]').click()
    wait = WebDriverWait(driver, 30)
    print('chegou ate aqui')

Then, the error after deploy on heroku:

2021-11-05T17:40:55.035807+00:00 app[worker.1]: code.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
2021-11-05T17:40:55.035820+00:00 app[worker.1]: driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
2021-11-05T17:40:55.035825+00:00 app[worker.1]: code.py:24: DeprecationWarning: firefox_binary has been deprecated, please pass in a Service object
2021-11-05T17:40:55.035825+00:00 app[worker.1]: driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
2021-11-05T17:40:55.540760+00:00 app[worker.1]: Traceback (most recent call last):
2021-11-05T17:40:55.540774+00:00 app[worker.1]: File "code.py", line 24, in <module>
2021-11-05T17:40:55.540947+00:00 app[worker.1]: driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
2021-11-05T17:40:55.540949+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 175, in __init__
2021-11-05T17:40:55.541113+00:00 app[worker.1]: self.service.start()
2021-11-05T17:40:55.541123+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 101, in start
2021-11-05T17:40:55.541249+00:00 app[worker.1]: self.assert_process_still_running()
2021-11-05T17:40:55.541250+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 113, in assert_process_still_running
2021-11-05T17:40:55.541359+00:00 app[worker.1]: raise WebDriverException(
2021-11-05T17:40:55.541409+00:00 app[worker.1]: selenium.common.exceptions.WebDriverException: Message: Service /app/vendor/geckodriver/geckodriver unexpectedly exited. Status code was: 64

Can anyone helps me how to solve it ?

Luís Eduardo
  • 52
  • 1
  • 6

1 Answers1

1

The following arguments:

  • -no-sandbox
  • -disable-gpu

perhaps are applicable to ChromeDriver / combo but Not Applicable to GeckoDriver / combo.

Remove the arguments and re-execute.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352