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

Cloudflare Captcha detected, unfortunately you haven't loaded an anti Captcha provider correctly via the 'captcha' parameter #172

Closed
chitosai opened this issue Jun 11, 2021 · 5 comments
Labels

Comments

@chitosai
Copy link

POST https://oauth.secure.pixiv.net/auth/token error: Cloudflare Captcha detected, unfortunately you haven't loaded an anti Captcha provider correctly via the 'captcha' parameter.
cloudscraper.exceptions.CloudflareCaptchaProvider: Cloudflare Captcha detected, unfortunately you haven't loaded an anti Captcha provider correctly via the 'captcha' parameter.

During handling of the above exception, another exception occurred:

pixivpy3.utils.PixivError: requests POST https://oauth.secure.pixiv.net/auth/token error: Cloudflare Captcha detected, unfortunately you haven't loaded an anti Captcha provider correctly via the 'captcha' parameter.

During handling of the above exception, another exception occurred:

RuntimeError: Error in login

I searched 'captch' in the repo but didn't find any documents on the parament. Can you tell me how to fix the issue?

@chitosai
Copy link
Author

I checked cloudscrap's readme and it looks like it requires a 3rd party captcha solver to deal with the issue?

I am so confused.. I did not change anything on my server, what caused the problem?
I see there are some replies recommending using a vpn or proxy, but I am getting the response from both my server at singapore and my computer at canada. It doesn't look like a issue caused by ip address?

@Xdynix
Copy link
Collaborator

Xdynix commented Jun 11, 2021

We never know what approach Cloudflare has done in terms of anti-bots and cause these captchas. Maybe it checked the cookie, or added a IP greylist, or it was simply random. pixivpy currently simply uses cloudscraper to handle some basic situations (#140).

As a monkey patch, you can try:

import cloudscraper


api = AppPixivAPI()

# Override the default cloud scraper created by pixivpy
# Refer to cloudscraper's doc for usage:
# https://github.com/venomous/cloudscraper#3rd-party-captcha-solvers
api.requests = cloudscraper.create_scraper(captcha={...})

# Other stuff as you normally did
api.auth(...)
...

In my personal experience on my own computer (in the US), even if the captcha exists in the first run, but it may disappear in the immediate second run. For me it is a random problem.

@chitosai
Copy link
Author

chitosai commented Jun 11, 2021

@Xdynix Thanks for the explain.

I have a script which runs every one hour, it refreshs access_token by auth() menthod.
I looked into my log and about three weeks ago auth() method began to occasionally return

"error": {"user_message": "", "message": "Error occurred at the OAuth process. Please check your Access Token to fix this. Error Message: invalid_grant", "reason": "", "user_message_details": {}}}

I did not notice that and about two weeks ago the error message turned into the captcha one I mentioned above. At first it occured occasionally, and till now it is a 100% captcha failure every hour.

So I guess I should clear my current access_token and try login again, unfortunately then I got

pixivpy3.utils.PixivError: [ERROR] auth() failed! check username and password.
HTTP 400: {"has_error":true,"errors":{"system":{"message":"Invalid grant_type parameter or parameter missing","code":1508}},"error":"invalid_grant"}

I searched it and find out it seems to be no longer possible to login in by username & password #158

So my question now has turned to.. how can I login in and get access_token now?
I read the readme but it does not provide new methods seemly.

api = AppPixivAPI()
# api.login("username", "password") # Not required

So sorry for the long confusing info, it takes some time for me to figure out what happened before...

@upbit
Copy link
Owner

upbit commented Jun 11, 2021

Due to #158 reason, password login no longer exist. Please use api.auth(refresh_token=REFRESH_TOKEN) instead

To get refresh_token, see @ZipFile Pixiv OAuth Flow or OAuth with Selenium/ChromeDriver

@upbit upbit added the question label Jun 11, 2021
@chitosai
Copy link
Author

@upbit Solved! Thank you so much for the help!

I didn't notice the instruction even it is at the first line..😅

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

3 participants