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

Login cookie issue (update user agent to fix) #1239

Open
cocokakao opened this issue Feb 28, 2023 · 26 comments
Open

Login cookie issue (update user agent to fix) #1239

cocokakao opened this issue Feb 28, 2023 · 26 comments
Labels

Comments

@cocokakao
Copy link

I reinstalled it.
I logged in and replaced the cookie, but the same phrase came out.


Trying to log in with saved cookie
Error at doLogin(): (<class 'mechanize._response.get_seek_wrapper_class..httperror_seek_wrapper'>, <httperror_seek_wrapper (urllib.error.HTTPError instance) at 0x1e0f201f250 whose wrapped object = <HTTPError 403: 'Forbidden'>>, <traceback object at 0x000001E0F01B7800>)
Traceback (most recent call last):
File "PixivUtil2.py", line 1524, in doLogin
File "PixivBrowserFactory.py", line 347, 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..httperror_seek_wrapper: HTTP Error 403: Forbidden

Cannot Login!
press enter to exit.

@PatrickL546 PatrickL546 mentioned this issue Feb 28, 2023
1 task
@Osprey-Hawk
Copy link

pixivutil.log
I'm having the same issue. I attached my own log with my login censored.

@xWTF
Copy link

xWTF commented Feb 28, 2023

The login request to https://www.pixiv.net/en/ is failing:

Trying to log in with saved cookie

send: b'CONNECT www.pixiv.net:443 HTTP/1.0\r\n'
send: b'\r\n'
send: b'GET /en HTTP/1.1\r\nAccept-Encoding: identity\r\nCookie: PHPSESSID=[REDACTED]\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36\r\nHost: www.pixiv.net\r\nConnection: close\r\n\r\n'

reply: 'HTTP/1.1 302 Found\r\n'
header: Date: Tue, 28 Feb 2023 [REDACTED] GMT
header: Content-Type: text/html; charset=UTF-8
header: Content-Length: 0
header: Connection: close
header: vary: User-Agent
header: x-host-time: 109
header: x-xss-protection: 1; mode=block
header: set-cookie: first_visit_datetime_pc=[REDACTED]; expires=Thu, 27-Feb-2025 [REDACTED] GMT; Max-Age=63072000; path=/; secure
header: location: /en/
header: strict-transport-security: max-age=31536000
header: x-frame-options: SAMEORIGIN
header: CF-Cache-Status: DYNAMIC
header: Set-Cookie: __cf_bm=[REDACTED]; path=/; expires=Tue, 28-Feb-23 [REDACTED] GMT; domain=.pixiv.net; HttpOnly; Secure; SameSite=None
header: Server: cloudflare
header: CF-RAY: [REDACTED]
header: alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

send: b'CONNECT www.pixiv.net:443 HTTP/1.0\r\n'
send: b'\r\n'
send: b'GET /en/ HTTP/1.1\r\nAccept-Encoding: identity\r\nCookie: PHPSESSID=[REDACTED]; first_visit_datetime_pc=[REDACTED]; __cf_bm=[REDACTED]\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36\r\nHost: www.pixiv.net\r\nConnection: close\r\n\r\n'

reply: 'HTTP/1.1 403 Forbidden\r\n'
header: Date: Tue, 28 Feb 2023 [REDACTED] GMT
header: Content-Type: text/html; charset=UTF-8
header: Transfer-Encoding: chunked
header: Connection: close
header: Permissions-Policy: accelerometer=(),autoplay=(),camera=(),clipboard-read=(),clipboard-write=(),fullscreen=(),geolocation=(),gyroscope=(),hid=(),interest-cohort=(),magnetometer=(),microphone=(),payment=(),publickey-credentials-get=(),screen-wake-lock=(),serial=(),sync-xhr=(),usb=()
header: Referrer-Policy: same-origin
header: X-Frame-Options: SAMEORIGIN
header: Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
header: Expires: Thu, 01 Jan 1970 00:00:01 GMT
header: Vary: Accept-Encoding
header: Server: cloudflare
header: CF-RAY: [REDACTED]
header: alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

Edit: Use solution by Nanoka if you're not running from source

A temporary workaround is to modify PixivBrowserFactory.py loginUsingCookie method to:

  • Load the cookie
  • Set self._myId (just hardcode it, it's temporary anyway)
  • Set self._isPremium
  • Return true directly without sending the request.

Other functionalities (fanbox login, download) seems to be working atm.

@biggestsonicfan
Copy link
Contributor

Wow I was just using it moments ago, if you had the utility still running, it would work, but now it won't.

@matsumotokenji
Copy link

same getting HTTP Error 403: Forbidden

@Nanoka
Copy link

Nanoka commented Feb 28, 2023

maybe related to #1209 as the solution i found that time seems to work now as well
change the useragent string to just "Mozilla/5.0" and it should work (try again if it fails)

@gnarf1975
Copy link

maybe related to #1209 as the solution i found that time seems to work now as well change the useragent string to just "Mozilla/5.0" and it should work (try again if it fails)

Doesn't work for me

@Nanoka
Copy link

Nanoka commented Feb 28, 2023

Doesn't work for me

is your config.ini set exactly like this:

useragent = Mozilla/5.0

which version are you running? did you try launching a new instance after the failed attempt? are you using proxy?

@halcatt
Copy link

halcatt commented Feb 28, 2023

maybe related to #1209 as the solution i found that time seems to work now as well change the useragent string to just "Mozilla/5.0" and it should work (try again if it fails)

Best answer! Worth to be highlighted

@DisasterInbound
Copy link

DisasterInbound commented Feb 28, 2023

maybe related to #1209 as the solution i found that time seems to work now as well change the useragent string to just "Mozilla/5.0" and it should work (try again if it fails)

I can also confirm it worked. I deleted the rest of the text, I only kept Mozilla/5.0 and I logged in this time

@Nanoka Nanoka mentioned this issue Feb 28, 2023
@Osprey-Hawk
Copy link

Can confirm. Worked perfectly. I tested it prior to modifying the INI and it had the error. With the change it had no issues.

@Uraratan
Copy link

Uraratan commented Mar 1, 2023

[Network]
useProxy = False
proxyAddress =
useragent = Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36
useRobots = True
timeout = 60
retry = 3
retryWait = 5
downloadDelay = 2
checkNewVersion = True
notifyBetaVersion = True
openNewVersion = True
enableSSLVerification = True

is what default settings is i guess ?

@dragontamer8740
Copy link
Contributor

dragontamer8740 commented Mar 3, 2023

Setting user-agent to just Mozilla/5.0 works.

To see the default settings you can either look in the source code or delete/rename your INI file and then let the program recreate it.

@VeggieJay
Copy link

maybe related to #1209 as the solution i found that time seems to work now as well change the useragent string to just "Mozilla/5.0" and it should work (try again if it fails)

works

@na3i09
Copy link

na3i09 commented Mar 13, 2023

Changing user-agent doesn't work for me while running from source on linux. Still get the 403 error.

@PatrickL546
Copy link
Contributor

@na3i09 "useragent = Mozilla/5.0" did you use that? if so, idk other workaround

@na3i09
Copy link

na3i09 commented Mar 14, 2023

@na3i09 "useragent = Mozilla/5.0" did you use that? if so, idk other workaround

yeah, no dice when using the source version.

@Nanoka
Copy link

Nanoka commented Mar 14, 2023

Changing user-agent doesn't work for me while running from source on linux. Still get the 403 error.

Try changing https://www.pixiv.net/en to https://www.pixiv.net in PixivBrowserFactory.py line 347:
https://github.com/Nandaka/PixivUtil2/blob/master/PixivBrowserFactory.py#L347

With this it may work without changing the user agent.

@Nandaka Nandaka pinned this issue Mar 26, 2023
@Nandaka Nandaka changed the title Login cookie issue Login cookie issue (update user agent to fix) Mar 26, 2023
@Nandaka Nandaka added the PSA label Mar 26, 2023
This was referenced Mar 26, 2023
@anon1593
Copy link

For those who have tried both and still have issues, Go to pixiv.net, log out, log back in, and replace the cookie in config.ini with the newly generated one.
That finally got it working again for the moment.
There seems to be a deeper issue going on.

@elina7
Copy link

elina7 commented May 4, 2023

useragent = Mozilla / 5.0 is not work
useragent = Mozilla/5.0 is working

@capSAR273
Copy link

I still cannot log in using the session cookie and the proper user agent.

@PatrickL546
Copy link
Contributor

Created a pull request #1281 Hopefully fixes http:403 forbidden and people's confusion

@JojoWalks
Copy link

MAN, this thread is making zero sense to me. I cant keep up

@xWTF
Copy link

xWTF commented Jan 27, 2024

MAN, this thread is making zero sense to me. I cant keep up

Hi, please kindly stop posting non-constructive comments that disturbs everyone subscribed to this issue or repo.

Also, I would appreciate it if you can stop downvoting a solution that has expired for nearly a year ¯\_(ツ)_/¯.

I've already pointed out that you should use the solution by Nanoka, which worked very well. My automation script run twice a day and never fails since I switched to that solution.

image

Pomax added a commit to Pomax/PixivUtil2 that referenced this issue Apr 20, 2024
Looks like Nandaka#1239 is still the case, with pixiv now blocking the current user agent, too. Switching it to the recommended value from 1239, however, works.
Pomax added a commit to Pomax/PixivUtil2 that referenced this issue Apr 20, 2024
Looks like Nandaka#1239 is still the case, with pixiv now blocking the current user agent, too. Switching it to the recommended value from 1239, however, works.
Pomax added a commit to Pomax/PixivUtil2 that referenced this issue Apr 20, 2024
This also removes the code that got commented off in Nandaka#1239, because either it's no longer need (so it doesn't need to be in the code at all) or it may be needed "sometimes" in which case it should probably live uncommented inside an `if` block.
Nandaka pushed a commit that referenced this issue Aug 1, 2024
* Change useragent to something that doesn't get blocked 

Looks like #1239 is still the case, with pixiv now blocking the current user agent, too. Switching it to the recommended value from 1239, however, works.

* Remove "dead" code

This also removes the code that got commented off in #1239, because either it's no longer need (so it doesn't need to be in the code at all) or it may be needed "sometimes" in which case it should probably live uncommented inside an `if` block.

* Link to the relevant README.md section

Added a link so people can easily get the information they need to fix the problem.

* (missing newline)
@AndrewHack242
Copy link

I'm having this issue now, just pulled main down to try to fix it, but it is persisting. I've logged out and back in to re-aquire my cookie from firefox multiple times but it continues to give me this error.

I had the thought that I may be populating the cookie incorrectly, but if I change the last character to make it invalid I get a different error:

Error at doLogin(): (<class 'mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper'>, <httperror_seek_wrapper (urllib.error.HTTPError instance) at 0x7f5785b98d40 whose wrapped object = <HTTPError 302: 'The HTTP server returned a redirect error that would lead to an infinite loop.\nThe last 30x error message was:\nFound'>>, <traceback object at 0x7f5785b3a000>) 
Traceback (most recent call last):
  File "/home/ahack/programming/PixivUtil2/PixivUtil2.py", line 1527, in doLogin
    result = __br__.loginUsingCookie()
  File "/home/ahack/programming/PixivUtil2/PixivBrowserFactory.py", line 354, in loginUsingCookie
    res = self.open_with_retry('https://www.pixiv.net')  # + self._locale)
  File "/home/ahack/programming/PixivUtil2/PixivBrowserFactory.py", line 208, in open_with_retry
    res = self.open(url, data, timeout)
  File "/home/ahack/programming/PixivUtil2/venv/lib/python3.10/site-packages/mechanize/_mechanize.py", line 257, in open
    return self._mech_open(url_or_request, data, timeout=timeout)
  File "/home/ahack/programming/PixivUtil2/venv/lib/python3.10/site-packages/mechanize/_mechanize.py", line 313, in _mech_open
    raise response
mechanize._response.get_seek_wrapper_class.<locals>.httperror_seek_wrapper: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
The last 30x error message was:
Found

So it seems like my cookie is correct and then something else is causing it to fail.

I have tried both
useragent = Mozilla/5.0 (X11; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0
which was copied out of my browser and
useragent = Mozilla/5.0
to no avail

@Uraratan
Copy link

Uraratan commented Sep 22, 2024

Nandaka, on pixiv fanbox i keep etting this

Configuration loaded.
Trying to log in FANBOX with saved cookie
Error getting FANBOX artist by id: 8594243 ==> Failed FANBOX Cloudflare CAPTCHA challenge, please check your cookie and user-agent settings.

i re appied
cf_clearance
cf_bm
cookieFanbox

the default pixiv worksfine just fanbox not and i have no clue what i do wrong

the view cookies i use this addon "cookie editor"

i have no clue what this cloudfare thing is

-edit

i think i came a step further by editing the useragent
useragent = Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0

now i get
image

Input: f2
Artist/Creator IDs = hitokuirou
End page (default is 0) =
Member IDs: ['hitokuirou']
Reading C:\Program Files (x86)\Pixiv Util (Artists)\config.ini ...
Configuration loaded.
Trying to log in FANBOX with saved cookie
FANBOX Login successful.
Getting artist information from https://api.fanbox.cc/creator.get?creatorId=hitokuirou
Member Url : https://www.pixiv.net/ajax/user/1510190/profile/all
Processing FanboxArtist(1510190, hitokuirou, 人喰瑯), page 1
Getting posts from https://api.fanbox.cc/post.listCreator?creatorId=hitokuirou&limit=10
Traceback (most recent call last):
File "PixivUtil2.py", line 1745, in main
File "PixivUtil2.py", line 1469, in main_loop
File "PixivUtil2.py", line 1001, in menu_fanbox_download_by_id
help='''Include Pixiv Sketch when processing member id (1). Default is False.''')
File "PixivFanboxHandler.py", line 50, in process_fanbox_artist_by_id
except PixivException as pex:
File "PixivBrowserFactory.py", line 1048, in fanboxGetPostsFromArtist
p_req = mechanize.Request(url)
File "PixivModelFanbox.py", line 575, in parsePosts
TypeError: list indices must be integers or slices, not str
Unknown Error, please check the log file: (<class 'TypeError'>, TypeError('list indices must be integers or slices, not str'), <traceback object at 0x00000213DE520980>)
press enter to exit.

@biggestsonicfan
Copy link
Contributor

@Uraratan This is an issue for Pixiv logins, not Fanbox. Your issue is a duplicate of #1361 and #1371. I suggest searching through existing issues before simply posting under a pinned issue.

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

No branches or pull requests