samapriya/geeup

Cannot run selsetup when $DISPLAY environment variable is not set

s-kganz opened this issue · 3 comments

Hello,

I'd like to use this package to upload a bunch of local shapefiles to Earth Engine. I am running Ubuntu 18.04 on WSL and installed geeup in a Conda 4.11.0 virtual environment. I loaded a virtual environment and ran pip install geeup. This succeeded, and then I get the following when running geeup init and geeup selsetup.

(base) ganzk@ganzk:/mnt/c/users/ganzk/desktop/lakes$ geeup init
Downloading from: https://github.com//mozilla/geckodriver/releases/download/v0.30.0/geckodriver-v0.30.0-linux64.tar.gz
 [*] 2.6 MB / 2.6 MB @ 3.1 MB/s [##################] [100%, 0s left]     
Use selenium driver path as /home/ganzk/anaconda3/lib/python3.7/site-packages/geeup
(base) ganzk@ganzk:/mnt/c/users/ganzk/desktop/lakes$ geeup selsetup
Enter your Username:  <omitted>
Enter your Password:  
sel_setup.py:33: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  executable_path=os.path.join(pathway, "geckodriver"), options=options
Traceback (most recent call last):
  File "sel_setup.py", line 72, in <module>
    authenticate()
  File "sel_setup.py", line 33, in authenticate
    executable_path=os.path.join(pathway, "geckodriver"), options=options
  File "/home/ganzk/anaconda3/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 183, in __init__
    keep_alive=True)
  File "/home/ganzk/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 268, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/ganzk/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 359, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/ganzk/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "/home/ganzk/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1

I then tried getting a Selenium browser in a Python script to generate a log file.

from selenium import webdriver
browser = webdriver.Firefox()

This generates a similar error as above along with a geckodriver.log. This file contains:

1639690655015	geckodriver	INFO	Listening on 127.0.0.1:63602
1639690655029	mozrunner::runner	INFO	Running command: "/usr/bin/firefox" "--marionette" "--remote-debugging-port" "63603" "-no-remote" "-profile" "/tmp/rust_mozprofileRG7qIk"
Error: no DISPLAY environment variable specified

From some Googling, it looks like Selenium needs to be run headless to work on WSL. This code snippet worked for me to get a browser running.

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
browser = webdriver.Firefox(options=options)
browser.get("http://google.com")
print("Headless firefox working")

I'm not sure how much work it is to make Selenium run headless in geeup, but it would be very helpful! Please let me know if I can provide any more information.

Did some digging, looks like sel_setup.py is missing the -headless argument. When I add options.add_argument("-headless") in the function authenticate, I get a little further. Now my error looks like this:

(base) ganzk@ganzk:~$ geeup selsetup
Enter your Username:  <omitted>
Enter your Password:  
sel_setup.py:34: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  executable_path=os.path.join(pathway, "geckodriver"), options=options
sel_setup.py:42: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  driver.find_element_by_xpath('//*[@id="openid-buttons"]/button[1]').click()
sel_setup.py:44: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  driver.find_element_by_xpath('//input[@type="email"]').send_keys(uname)
sel_setup.py:45: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  driver.find_element_by_xpath("//div[@id='identifierNext']").click()
sel_setup.py:47: DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead
  driver.find_element_by_xpath('//input[@type="password"]').send_keys(passw)
Message: Unable to locate element: //input[@type="password"]
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:181:5
NoSuchElementError@chrome://remote/content/shared/webdriver/Errors.jsm:393:5
element.find/</<@chrome://remote/content/marionette/element.js:299:16

Hi @s-kganz
I would recommend using the cookies method to achieve what you are trying to achieve, GEE has also made using selenium problematic even with authenticated accounts, you can find more information here . In the future version I will remove selenium support to allow people to just use cookies. Hope this will help, feel free to reopen the issue if this doesn't work for you

https://samapriya.github.io/geeup/projects/cookies_setup/

and then use the following with the method flag --method cookies
https://samapriya.github.io/geeup/projects/table_upload/

so something like

geeup tabup --source "full path to folder with Zipped Shapefiles/CSV files" --dest "Full path for upload to Google Earth Engine, e.g. users/pinkiepie/folder" --user "email@domain.com authenticated and used with GEE" --method "cookies"

Ah, did not see that method. Many thanks, works as expected now.