Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't login in PixivUtil2 #1397

Open
Ouxhi opened this issue Jan 8, 2025 · 6 comments
Open

Can't login in PixivUtil2 #1397

Ouxhi opened this issue Jan 8, 2025 · 6 comments

Comments

@Ouxhi
Copy link

Ouxhi commented Jan 8, 2025

I'm using the latest release of PixivUtil2 (v20240703). As of today, when I try to launch PixivUtil2, I get an error message:

Trying to log in with saved cookie
Logging in, return url: https://www.pixiv.net/en/
Login successful.
Unable to get User Id, please check your cookie.
Please follow the instruction in https://github.com/Nandaka/PixivUtil2/issues/814#issuecomment-711182644
Error at doLogin(): (<class 'PixivException.PixivException'>, PixivException('Unable to get User Id, please check your cookie.'), <traceback object at 0x00000163D29D6940>)
Traceback (most recent call last):
  File "PixivUtil2.py", line 1527, in doLogin
  File "PixivBrowserFactory.py", line 371, in loginUsingCookie
  File "PixivBrowserFactory.py", line 604, in getMyId
PixivException.PixivException: PixivException(100 Unable to get User Id, please check your cookie., hasDumpPage=Y)

Cannot Login!

I logged out of Pixiv site and logged back in, copied the new cookie value over to config.ini, but I'm still getting the same error message in PixivUtil2. I also tried the method of changing my password and getting the cookie, but that didn't work either. I also updated my user-agent with information from my Firefox browser, but that didn't fix it either.

@Ouxhi
Copy link
Author

Ouxhi commented Jan 16, 2025

I still can't login in PixivUtil2. I tried using Chrome browser user-agent and cookie to login, but now I get a different error:

Trying to log in with saved cookie
Error at doLogin(): (<class 'mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper'>, <httperror_seek_wrapper (urllib.error.HTTPError instance) at 0x1e21b21bbe0 whose wrapped object = <HTTPError 403: 'Forbidden'>>, <traceback object at 0x000001E21B256940>)
Traceback (most recent call last):
  File "PixivUtil2.py", line 1527, in doLogin
  File "PixivBrowserFactory.py", line 351, in loginUsingCookie
  File "PixivBrowserFactory.py", line 207, in open_with_retry
  File "mechanize\_mechanize.py", line 257, in open
  File "mechanize\_mechanize.py", line 313, in _mech_open
mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper: HTTP Error 403: Forbidden

Cannot Login!

I put in the Chrome user-agent and the Chrome cookie, and the above is the resulting error. I'm able to login and use Pixiv website on both browsers completely fine, so I don't understand why my login information isn't working in PixivUtil2 anymore. Anyone have any idea what else I can do?

edit: I shortened the user-agent to just Mozilla/5.0 while using the chrome information. The result is the same error message from my first post.

@mrxmm149
Copy link

tldr, my bodged solution:

diff --git a/PixivBrowserFactory.py b/PixivBrowserFactory.py
index 1ecfdd7..9164fa6 100644
--- a/PixivBrowserFactory.py
+++ b/PixivBrowserFactory.py
@@ -594,7 +594,7 @@ class PixivBrowser(mechanize.Browser):
                 PixivHelper.print_and_log('info', f'My User Id: {self._myId}.')
             else:
                 # var dataLayer = [{ login: 'yes', gender: "male", user_id: "3145410", lang: "en", illustup_flg: 'not_uploaded', premium: 'no', }];
-                temp = re.findall(r"var dataLayer = .*user_id: \"(\d+)\"", parsed)
+                temp = re.findall(r"var dataLayer = .*user_id:'(\d+)'", parsed)
                 if self._myId == 0 and temp is not None and len(temp) > 0:
                     self._myId = int(temp[0])
                     PixivHelper.print_and_log('info', f'My User Id: {self._myId}.')

i.e. change temp = re.findall(r"var dataLayer = .*user_id: \"(\d+)\"", parsed) in line 597 of PixivBrowserFactory.py to temp = re.findall(r"var dataLayer = .*user_id:'(\d+)'", parsed).


I received the same error message and I took a look in it.

In my case, dataLayer received from Pixiv was like this:

'use strict'; var dataLayer = [{login:'yes',gender:'<MYGENDER>',user_id:'<MYID>',lang:'ja',illustup_flg:'not_uploaded',premium:'no',default_service_is_touch:'yes'}];

Not sure this is my fault, I did tinker some config values while trying to solve issue by searching through issues here.
But both values in my Chrome browser and that PixivUtil received seems to be in this format.

I don't think this warrants deep debug dive, but maybe proper parsing of dataLayer array instead of regex parsing would be nice.
I am happy to do some work for you, but I currently don't know much about js parsing in python, so ask me if you want me to then I will start looking for options.

Always grateful for your work, Nandaka and all contributors!

@bubbee23
Copy link

I have same problem too.

about 2 week before this error message happen, I'm use this version and it work normally.

I have done fix by following instruction, I'm still get this error.

Thank you in advance for fixing it.

@bubbee23
Copy link

Where I can find this file PixivBrowserFactory.py in .exe version?

@codingbyme495
Copy link

i got this same error 403

@mrxmm149
Copy link

mrxmm149 commented Feb 1, 2025

@bubbee23

Where I can find this file PixivBrowserFactory.py in .exe version?

You have to run from the source code. Not super easy in Windows especially for non-programmers, but it can be done.
Follow https://github.com/Nandaka/PixivUtil2/wiki/IDE-Enviroment-(Windows) and come back if you are stuck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@Ouxhi @bubbee23 @mrxmm149 @codingbyme495 and others