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

danbooru cloudflare 403 no matter what #6496

Closed
Hugs288 opened this issue Nov 18, 2024 · 6 comments
Closed

danbooru cloudflare 403 no matter what #6496

Hugs288 opened this issue Nov 18, 2024 · 6 comments

Comments

@Hugs288
Copy link

Hugs288 commented Nov 18, 2024

tried with cookies, login, multiple user agents, etc, while i can view links fine in web browsers gallery-dl always gives me cloudflare challenge 403.

maybe this has something to do with tor? i use tor with socks5 to access danbooru.

@mikf
Copy link
Owner

mikf commented Nov 18, 2024

Danbooru responds with 403 errors when using a standard/default User-Agent header in a script, which hasn't been the case for gallery-dl since v1.25.0 (cbe4769).

What's your output for gallery-dl --version?

@Hugs288
Copy link
Author

Hugs288 commented Nov 18, 2024

1.27.7

@mikf
Copy link
Owner

mikf commented Nov 18, 2024

Then it's probably tor.

edit:

$ gallery-dl --proxy socks5h://127.0.0.1:9050 https://danbooru.donmai.us/posts/686612
[danbooru][warning] Cloudflare challenge
[danbooru][error] HttpError: '403 Forbidden' for 'https://danbooru.donmai.us/posts/686612.json'

$ gallery-dl https://danbooru.donmai.us/posts/686612
./danbooru/danbooru_686612_206aee80734e0e5ab65aff450fdffa31.jpg

@Hugs288
Copy link
Author

Hugs288 commented Nov 18, 2024

yeah i figured, but imgbrd grabber works fine with tor and socks5

@mikf
Copy link
Owner

mikf commented Nov 20, 2024

As it turns out, accessing the API through Tor always triggers a Cloudflare challenge page, even in a browser.

Letting your browser solve the challenge by visiting an API page like https://danbooru.donmai.us/posts/686612.json, and using exported cookies and browser User-Agent would work,

$ gallery-dl --cookies-from firefox:/tmp/ --user-agent browser --proxy socks5h://127.0.0.1:9050 https://danbooru.donmai.us/posts/686612
[cookies][info] Extracted 2 cookies from Firefox
./danbooru/danbooru_686612_206aee80734e0e5ab65aff450fdffa31.jpg

but the danbooru code currently overwrites any custom User-Agent header.

self.session.headers["User-Agent"] = util.USERAGENT

@Hugs288
Copy link
Author

Hugs288 commented Nov 21, 2024

yep, removed that line of code from danbooru.py, works perfectly now.

mikf added a commit that referenced this issue Nov 26, 2024
ignore 'extractor.user-agent' if it is the default useragent value
and an extractor wants to set its own custom value
@mikf mikf closed this as completed Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants