Nandaka / PixivUtil2

Download images from Pixiv and more!
http://nandaka.devnull.zone/
BSD 2-Clause "Simplified" License
2.35k stars 257 forks source link

Incorrect OAuth error when retrieving empty member gallery #966

Closed photonometric closed 3 years ago

photonometric commented 3 years ago

Ran into this while running a 'get list' [pixivutil20210421/win10 enterprise]. This is my long-running config and the installed version is several months old with no other problems.

Upon reaching a certain member id [247961], the list process halts immediately wth the following error:

Processing Member Id: 247961
Page
Member Url: https://www.pixiv.net/ajax/user/247961/profile/all
Using OAuth to retrieve member info for: 247961
Instructions:
1. This will open a new browser to login to Pixiv site to get the code.
1b. In case the browser will not open, or you are using an headless server, use
this link: https://app-api.pixiv.net/web/v1/login?code_challenge=xxxxxxxx&code_challenge_method=S256&client=pixiv-android
2. Open dev console (F12) and switch to network tab.
3. Enable persistent logging ("Preserve log").
4. Type into the filter field: 'callback?'.
5. Proceed with Pixiv login.
6. After logging in you should see a blank page and request that looks like this:
   'https://app-api.pixiv.net/web/v1/users/auth/pixiv/callback?state=...&code=...'
7. Copy value of the code param into the prompt and hit the Enter key.
Press enter when you ready.

At first I tried the OAuth session id process, which I couldn't complete at the time (some browser error I think), but pixivutil kept working as usual when I tried member_id or fanbox downloads. Then I discovered that this artist currently has a completely empty gallery:

2021-06-12_9-21-29

Unfortunately, the log file shows no problems except deciding to go to OAuth, but doesn't explain "why" (DEBUG level)

2021-06-11 22:41:31,041 - PixivUtil20210421 - INFO - Using OAuth to retrieve member info for: 247961
2021-06-11 22:41:31,042 - PixivUtil20210421 - DEBUG - Getting member information: 247961
2021-06-11 22:41:31,042 - PixivUtil20210421 - INFO - Login to OAuth using refresh token.
2021-06-11 22:41:32,381 - PixivUtil20210421 - INFO - OAuth Refresh Token invalid, Relogin needed.

My download dir has 72 pics from when this author did have content, and has a database entry from when I last downloaded files that are dated 2018-11-20 (I don't know what the rest of this database->'list by member_id info means, but probably not relevant)

member_id? 247961
         247961
         ????@??

         2018-11-18 00:18:19
         2018-12-13 09:01:08
         24770128
         0
         None

Deleting this artist from the database and re-trying leads to the same error, and trying this artist on a fresh install does as well. I tried another randomly typed member_id which also has an empty gallery, and it has the same result.

So it seems likely the program simply can't handle trying to download 0-content members, and somehow reads it as identical to accessing a normal gallery with an incorrect cookie. I don't want to test changing my OAuth since it doesn't always go smoothly in my browsers (or maybe brain), but even if going through the requested OAuth process yields a more graceful explanatory message, it's still an incorrect 'diagnosis,' since these galleries show as empty even when not logged in.

The obvious workaround is to just delete offending old artists from the database. Not sure if some users might have setups in which retaining that info of 'lost' sources might be helpful in identifying their files? Can also be a circular process if one e.g. makes a list of artist folders to update, from older databases which contain more of these artists who found religion or became politicians xp which re-introduces more confusing errors which need to be IDed and deleted.

So not a critical issue at all, except for the misleading error. I suppose the desired outcome would be a simple message like for a non-existant memberid: pageData=b'{"error":true,"message":"User has left pixiv or the user ID does not exist."

Thanks as always for your (and our other friends') most excellent work! n___n

photonometric commented 3 years ago

This sounds a bit similar to the previous issue #965, but that has a more specific certificate message(?), and the example member gallery in that example was not an empty gallery.

bluerthanever commented 3 years ago

well... i don't quite think the error message is misleading.

in this procedure around where the error happens: PixivUtil2 tries to get all work ids from API https://www.pixiv.net/ajax/user/{user_id}/profile/all if the creator has no works (empty gallery), PixivUtil2 would need to use OAuth to get creator information. if PixivUtil2 can't get through OAuth, it throws an exception saying so.

it's not that Pixivutil2 can't get the information, but that you didn't give what it needs for it.

i think what you want would be more like to skip processing members who have empty galleries.

Nandaka commented 3 years ago

should be implemented in the latest version

photonometric commented 3 years ago

Thanks so much for fixing! <3 And thank you @bluerthanever for the clarifying comment...I meant the error message in the program output, but had mistakenly pasted the log file twice in my original post. Indeed I wasn't trying to comment on the code and API interaction, but the general UI experience of the situation ^^

bluerthanever commented 3 years ago

=) you are so welcome