mikf / gallery-dl

Command-line program to download image galleries and collections from several image hosting sites
GNU General Public License v2.0
11.38k stars 929 forks source link

[Twitter] Login Configs all set but not working [Err 401 Unauthorized] #5445

Closed vsatyamesc closed 4 months ago

vsatyamesc commented 5 months ago

[twitter][error] 401 Unauthorized (Could not authenticate you)

Tried using the same credentials to login in incognito and working but not on gallery-dl

mikf commented 5 months ago

Try using cookies directly since username & password don't seem to work for you.

Scrooge200FES commented 5 months ago

I'm having the same problem, and when I do sign in with -u and -p, I get rate limited. Here's what I'm using:

gallery-dl --cookies-from-browser firefox https://twitter.com/hourlyvasterror/status/1762904246624649229 [cookies][info] Extracted 3176 cookies from Firefox [twitter][error] 401 Unauthorized (Could not authenticate you)

Scripter17 commented 5 months ago

For me at least, the cookies stop working after a bit and gallery-dl has to try logging in, at which point it 401's

rautamiekka commented 5 months ago

For me at least, the cookies stop working after a bit and gallery-dl has to try logging in, at which point it 401's

If you actively use the same cookies you DL with, then yeah they will, it's a normal function of them.

vlf commented 5 months ago

It seems like twitter has implemented some even stricter anti-bot measures.

Rate limiting was all good, but few days ago after going through ~200 accounts ([-A 2] so around 500 downloads with random sleep of 2-10s) all of my sessions for that account got invalidated and was forcefully logged out on PC, while on mobile the app asked to verify if I'm a human. To be fair, I was also posting/changing profile for that account during that time, so that might have triggered the detection algorithm as well, not just pure request count and hitting rate limit.

Using secondary account from the same origin IP seems to be working just fine. This leads me to believe the account itself can get flagged as "potential bot" that requires some additional verification/challenge. Strangely enough logging in to the flagged account on PC again, didn't trigger any challange/captcha, but still returns 401 when attempting login using gallery-dl u/p.

plshelpidkwhatimdoing commented 5 months ago

I just got this error and like vlf said logging into the account didn't give me an arkose. If you have "logout": "true" in your gallery-dl.conf like I did, removing it and running --clear-cache twitter seems to have fixed it for me.

dieu commented 5 months ago

I just got this error and like vlf said logging into the account didn't give me an arkose. If you have "logout": "true" in your gallery-dl.conf like I did, removing it and running --clear-cache twitter seems to have fixed it for me.

didn't help me :( same error

[twitter][info] Requesting guest token
[twitter][info] Logging in as <user_name>
[twitter][error] AuthorizationError: Login required

with cookies:

[cookies][warning] Failed to decrypt cookie (AES-CBC Unicode)
[cookies][info] Extracted 340 cookies from Chrome (88 could not be decrypted)
[twitter][info] Requesting guest token
[twitter][error] 401 Unauthorized (Could not authenticate you)
dieu commented 5 months ago

I just got this error and like vlf said logging into the account didn't give me an arkose. If you have "logout": "true" in your gallery-dl.conf like I did, removing it and running --clear-cache twitter seems to have fixed it for me.

Could you share your config?

vsatyamesc commented 5 months ago

I just got this error and like vlf said logging into the account didn't give me an arkose. If you have "logout": "true" in your gallery-dl.conf like I did, removing it and running --clear-cache twitter seems to have fixed it for me.

Will try and check results

plshelpidkwhatimdoing commented 5 months ago

Could you share your config?

Sure, hope it helps:

    "extractor": {
        "twitter": {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0",
            "username": "username",
            "password": "password",
            "text-tweets": "true",
            "postprocessors": [
                {
                    "name": "metadata",
                    "event": "post",
                    "filename": "{tweet_id}_content.txt",
                    "mode": "custom",
                    "format": "{content}"
                }
            ]
        },
vlf commented 5 months ago

I just got this error and like vlf said logging into the account didn't give me an arkose. If you have "logout": "true" in your gallery-dl.conf like I did, removing it and running --clear-cache twitter seems to have fixed it for me.

Clearing cache did help in my case, thanks!

vsatyamesc commented 5 months ago

clearing cache helped

vsatyamesc commented 5 months ago

I've set --sleep 0.9 tried using 4 concurrent different user download and it all working without limiting. Apparently, Twitter is also limiting Browser downloads too. So its not just a problem of gallery-dl

a84r7a3rga76fg commented 5 months ago

It'll force you to re-login and maybe solve a captcha if you download too many files in one day

plshelpidkwhatimdoing commented 5 months ago

Clearing cache did help in my case, thanks!

clearing cache helped

Glad it helped

dieu commented 5 months ago

Could you share your config?

Sure, hope it helps:

    "extractor": {
        "twitter": {
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0",
            "username": "username",
            "password": "password",
            "text-tweets": "true",
            "postprocessors": [
                {
                    "name": "metadata",
                    "event": "post",
                    "filename": "{tweet_id}_content.txt",
                    "mode": "custom",
                    "format": "{content}"
                }
            ]
        },

thanks, it helped.

mikf commented 5 months ago

I've updated the login code a bit to handle email verification codes, 2FA tokens, and provide better(?) errors: 9e5d65fbf3a83958d98ad28dadea89a2a14c4fb7

There's now also a new option to re-login when receiving a "Could not authenticate you" error (enabled by default): 85bbb594839e83a407fdd6f9a66489355c5aafa6