eggplants / get-pixivpy-token

Get your Pixiv token easily (for running upbit/pixivpy)
MIT License
117 stars 9 forks source link

Browser window opened even when headless is set, the login form isn't filled #118

Closed exentio closed 8 months ago

exentio commented 8 months ago

When attempting the login, the headless option isn't respected, and the login doesn't happen as the login form isn't filled, ending in a crash.

The current code in gppt.py masks the real exception:

except TimeoutException as err:
    self.driver.close()
    msg = "Failed to login. Please check your information or proxy. (Maybe restricted by pixiv?)"
    raise ValueError(msg) from err

And I get this error:

(venv) ex@Nanami-Ao ~/p/twitter-to-pixiv-migration-v2 [0|1]> python test.py
Traceback (most recent call last):
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/gppt/gppt.py", line 164, in __wait_for_redirect
    WebDriverWait(self.driver, 20).until(EC.url_matches(f"^{REDIRECT_URI}"))
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/selenium/webdriver/support/wait.py", line 105, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/test.py", line 13, in <module>
    print(get_refresh_token())
          ^^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/test.py", line 9, in get_refresh_token
    refresh_token = g.login(username="XXXXX", password="XXXXX")["refresh_token"]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/gppt/gppt.py", line 75, in login
    self.__wait_for_redirect()
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/gppt/gppt.py", line 169, in __wait_for_redirect
    raise ValueError(msg) from err
ValueError: Failed to login. Please check your information or proxy. (Maybe restricted by pixiv?)

So I changed it:

except TimeoutException as err:
    print(err)
    self.driver.close()

And now I get the real crash log:

(venv) ex@Nanami-Ao ~/p/twitter-to-pixiv-migration-v2 [0|1]> python test.py
Message: 

Traceback (most recent call last):
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/test.py", line 13, in <module>
    print(get_refresh_token())
          ^^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/test.py", line 9, in get_refresh_token
    refresh_token = g.login(username="XXXXX", password="XXXXX")["refresh_token"]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/gppt/gppt.py", line 78, in login
    code = self.__parse_log()
           ^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/gppt/gppt.py", line 142, in __parse_log
    perf_log = self.driver.get_log("performance")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 1031, in get_log
    return self.execute(Command.GET_LOG, {"type": log_type})["value"]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 348, in execute
    self.error_handler.check_response(response)
  File "/home/ex/projects/twitter-to-pixiv-migration-v2/venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSessionIdException: Message: invalid session id

I'm currently running this on a virtual env on Linux, with version 4.0.0 of the library, and I have the latest versions of Google Chrome (121.0.6167.139) and Chromedriver (121.0.6167.85), although the newly implemented Selenium Manager should be downloading the latest version itself and use the downloaded executable.

This problem didn't happen with the fixes I sent in #114 and it's probably an aftermath of the refactoring done in #116 and I'll try to investigate the root of the problem myself, but the various changes have been force-pushed, making it harder to look at the changes in the code. I am guilty of force-pushing myself, but only in minor instances. You should never force-push such important commits, it's really bad practice.