subzeroid / instagrapi

🔥 The fastest and powerful Python library for Instagram Private API 2024
https://hikerapi.com/p/bkXQlaVe
MIT License
4.37k stars 684 forks source link

[BUG] instagrapi.exceptions.BadPassword even with the correct password and login #1498

Open R-LP opened 1 year ago

R-LP commented 1 year ago

Describe the bug instagrapi.exceptions.BadPassword: The password you entered is incorrect. Please try again.

To Reproduce

from instagrapi import Client
import os

from dotenv import load_dotenv
load_dotenv()

def post_to_instagram(username, password, image_path, caption):
    cl = Client()
    cl.login(username, password)

username = os.getenv("INSTAGRAM_USERNAME")
password = os.getenv("INSTAGRAM_PASSWORD")

print(username)
print(password)

image_path = "e97.png"
caption = "I love creating digital art "

post_to_instagram(username, password, image_path, caption)

Traceback

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 360, in _send_private_request
    response.raise_for_status()
  File "/Users/rodolphe.berthome/Library/Python/3.8/lib/python/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://i.instagram.com/api/v1/accounts/login/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "upload_to_instagram.py", line 46, in <module>
    post_to_instagram(username, password, image_path, caption)
  File "upload_to_instagram.py", line 10, in post_to_instagram
    cl.login(username, password)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 432, in login
    logged = self.private_request("accounts/login/", data, login=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 533, in private_request
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 518, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 407, in _send_private_request
    raise BadPassword(**last_json)
instagrapi.exceptions.BadPassword: The password you entered is incorrect. Please try again.

Expected behavior My password is correct as i just logged on my browser and my mobile with the exact same login.

adw0rd commented 1 year ago

I can't reproduce it, figure it out yourself and send us your fixes as PR if the bug really exists

R-LP commented 1 year ago

i've tried everything possible, i'm connected on my browser with the same login/password as i use in the script, but on the script i keep getting bad password.

How can i manually export the session information from my browser to dump it to session.json to bypass that ?

yueqingliang1 commented 1 year ago

I got the same error.

erhaem commented 1 year ago

The problem might be in .env. Instead, try hardcoded approach like this:

username = "YOUR USERNAME HERE"
password = "YOUR PASSWORD HERE"
yueqingliang1 commented 1 year ago

Where is .env?

R-LP commented 1 year ago

already tried with hardcoded username and password, got the same error "Bad Password" im logged in my browser with the exact same credentials (even copy/pasted), is there a way to export the session info from the developper tools of the browser to use in instragrapi ?

adw0rd commented 1 year ago

@R-LP you can copy sessionid from cookies and try to log in via cl.login_by_sessionid(sessionid) or are you asking something else?

yueqingliang1 commented 1 year ago

Thanks @adw0rd. I can log in by both sessionid and password now. However, it comes to another issue, which is "HTTPError: 401 Client Error: Unauthorized for url:..." as someone raised before. In this case, I can only extract the information of one post then the error occurred.

adw0rd commented 1 year ago

Thanks @adw0rd. I can log in by both sessionid and password now. However, it comes to another issue, which is "HTTPError: 401 Client Error: Unauthorized for url:..." as someone raised before. In this case, I can only extract the information of one post then the error occurred.

it at a call of what method? try cl.inject_sessionid_to_public()

R-LP commented 1 year ago

@adw0rd, i've tried the following: I'm connected on instagram on my browser, on the browser cookies I copy the session_id Then I execute the following, as you suggested with the login_by_sessionid

cl = Client()
session_id = "612123572xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
cl.login_by_sessionid(session_id)

but got the following:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 360, in _send_private_request
    response.raise_for_status()
  File "/Users/rodolphe.berthome/Library/Python/3.8/lib/python/site-packages/requests/models.py", line 960, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://i.instagram.com/api/v1/feed/timeline/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "upload_to_instagram.py", line 108, in <module>
    print(cl.get_timeline_feed())
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 241, in get_timeline_feed
    return self.private_request(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 533, in private_request
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 518, in private_request
    self._send_private_request(endpoint, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 386, in _send_private_request
    raise LoginRequired(response=e.response, **last_json)
instagrapi.exceptions.LoginRequired: login_required

Then when I'm back at my browser I got disconnected from my session, I refresh the page and need to relogin again from the browser.

So it keeps working from the browser but not from the script 🥲

Krumil commented 1 year ago

I'm also getting the "instagrapi.exceptions.BadPassword: The password you entered is incorrect. Please try again." error. @R-LP Did you find the reason behind this or di you just change the script to use cl.login_by_sessionid(session_id) method? Thanks

R-LP commented 1 year ago

I haven't find the reason for BadPassword. Also it doesn't work either with the session_id. So basically so far nothing is working. 🥲

falexet commented 1 year ago

Encountered the same issue. Was able to resolve it by changing password of Instagram account.

Hope this helps.

R-LP commented 1 year ago

I've followed the steps of @falexet Also realized that when changing the browser (to Chrome), when trying to login with the right password on the UI, got the bad password error.

Changed the password in the account center, managed to connect with both Safari and Chrome. But still got the bad password error with the script.

Also, here are the logs of the login:

https://i.instagram.com/api/v1/launcher/sync/
retro.routes [200] POST https://i.instagram.com/api/v1/launcher/sync/ (269.0.0.18.75, OnePlus 6T Dev)
https://i.instagram.com/api/v1/accounts/login/
retro.routes [400] POST https://i.instagram.com/api/v1/accounts/login/ (269.0.0.18.75, OnePlus 6T Dev)

The password is correct for sure, so my guess is that there is a problem with the user-agent or other information related to the login, maybe it's the "OnePlus 6T Dev" device that is blocked?

MartianDominic commented 1 year ago

Did all of what you guys recommended. Changed the password, logged out, copied session id, even changed a user agent to another phone model, still nothing works. It log's in, fetches user id from url, fetched media ids and when it goes to like them it logs me out, then gives 400 error, password is incorrect, 403 forbidden for url.

Could it be the cause of update && upgrade I ran today on ubuntu? When someone solves it, would appreciate you share will all of us, thanks!

falexet commented 1 year ago

So this morning the issue is back. Didn't figure out way to resolve it yet.

Krumil commented 1 year ago

I seriously don't know what's happening but I'm getting this when logging in-private browsing but not when logging normally in the browser. Don't know if this helps. Still not working codewise

sznyk5252 commented 1 year ago

I have exactly the same problem as you, same error with login and password and same error when i try to log in with session id. I try the exact same code on Windows 10 and Linux using google colaboratory on the same browser, and it works on windows but not on Linux

adw0rd commented 1 year ago

It is possible that Instagram now blocks accounts like this. Try changing your proxy, you should try

MartianDominic commented 1 year ago

Maybe it's updated chromium?Sent from my Galaxy -------- Original message --------From: sznyk5252 @.> Date: 01/08/2023 20:11 (GMT+02:00) To: adw0rd/instagrapi @.> Cc: MartianDominic @.>, Manual @.> Subject: Re: [adw0rd/instagrapi] [BUG] instagrapi.exceptions.BadPassword even with the correct password and login (Issue #1498) I have exactly the same problem as you, same error with login and password and same error when i try to log in with session id. I try the exact same code on Windows 10 and Linux using google colaboratory on the same browser, and it works on windows but not on Linux

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

ManeFunction commented 1 year ago

It's definitely Instagram fighting bots moment, got the same error exactly 2 days ago from flawlessly working script for months w/o any changes. Tried everything, but w/o any success. The strange moment is that I can understand if I'm getting this error from my server on Google Clouds, there is a strange device ID and different location, but even if I launch my script locally on my Mac from home – nevermind, the same error. So I'm really curious how are they track scripts, but not location and/or device.

MartianDominic commented 1 year ago

I am not using proxy, but connecting locallySent from my Galaxy -------- Original message --------From: ... @.*> Date: 01/08/2023 21:54 (GMT+02:00) To: *./instagrapi @.> Cc: MartianDominic @.>, Manual @.> Subject: Re: [**./instagrapi] [BUG] instagrapi.exceptions.BadPassword even with the correct password and login (Issue #1498) It is possible that Instagram now blocks accounts like this. Try changing your proxy, you should try

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

falexet commented 1 year ago

I suspect they might be looking into the headers we provide.

Tried different instagram version/User Agent without success (running from local Mac).

@ManeFunction are you using default UA/Instagram version headers (Instagram 269.0.0.18.75 Android (26/8.0.0; 480dpi; 1080x1920; OnePlus; 6T Dev; devitron; qcom; en_US; 314665256)?

MartianDominic commented 1 year ago

I tried using proxies to login through hidemyacc.com. It just blocks instagram whole, every other work, Instagram blocked.Sent from my Galaxy -------- Original message --------From: Ilia Petrov-Komotskii @.> Date: 02/08/2023 00:36 (GMT+02:00) To: adw0rd/instagrapi @.> Cc: MartianDominic @.>, Manual @.> Subject: Re: [adw0rd/instagrapi] [BUG] instagrapi.exceptions.BadPassword even with the correct password and login (Issue #1498) It's definitely Instagram fighting bots, got the same error exactly 2 days ago w/o any changes from flawlessly working script for months. Tried everything, but w/o any success. The strange moment is that I can understand if I'm getting this error from my server on Google Clouds, there is a strange device ID and different location, but even if I launch my script locally on my Mac from home – nevermind, the same error. So I'm really curious how they track scripts, but not location and/or device.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

ManeFunction commented 1 year ago

@falexet if this header is within instagrapi, yes, I'm using default. Is there a public method to change it?

MartianDominic commented 1 year ago

@ManeFunction I personally have a venv, and went into the auth code part. You may explore that endpoint through github library locally

ManeFunction commented 1 year ago

Not sure if I did it right, but I've look at the original code and made my own device info like this:

"app_version": "294.0",
"os_version": "16.6",
"dpi": "458dpi",
"resolution": "2688×1242",
"manufacturer": "Apple",
"device": "iPhone12,3",
"model": "iPhone 11 Pro",
"cpu": "A13 Bionic",
"build_id": "20G75",

Still the same "wrong password" response :(

falexet commented 1 year ago

@ManeFunction these methods allow to get current settings and change them including the UA

cl.get_settings() cl.set_settings(settings)

As an option user agent can be set directly cl.set_user_agent('blah blah')

One way to debug this would be to obtain actual headers sent by native Android Instagram app using something like MITM, and then replicate those in the bot. I don't plan to do that for at least couple of days though since I am busy.

ManeFunction commented 1 year ago

@falexet I'm using cl.set_device(Dict), is it ok?

R-LP commented 1 year ago

Anybody managed to login with instagrapi ?

mohebbi-1386 commented 1 year ago

Hello Do not be tired Good time

code:

from instagram import client
A
cl = Client()
cl.login('username', 'password')

error: instagrapi.exceptions.BadPassword: The password you entered is incorrect. Please try again. ....

I tried the following to fix this problem, but it didn't fix the problem:

  1. Double-check your Instagram username and password for correctness
  2. I checked the code and this error with several Instagram accounts and several different usernames and passwords.
  3. Disable two-factor authentication for your account temporarily and see if that resolves the issue.

please check it.

redobsi commented 1 year ago

same issue here

thetemplateblog commented 1 year ago

Same issue

redobsi commented 1 year ago

Even with a proxy, different proxies, new accounts created on different devices. It ain't working, also it gets instantly the ip of the IP that creates the account blocked & the account gets it's password changed. There are three or four errors that occurs to the same problem. Bad password, login required, wait a moment & try again later. Tried using : SOAX, Iproyal, proximate & webshares

notfounnd commented 1 year ago

The same started here this week. Yesterday I solve my problem using the handler to get 2FA code email. Today login process is failing again.

streamcon commented 1 year ago

Same issue

sunlightface commented 1 year ago

Continuing Same issue after yesterday

MartianDominic commented 1 year ago

@adw0rd Hey Mikhail, I know you're super busy and you said you couldn't replicate the problem. Could you take a look at it again, since so many of us are experiencing it and it's not a one-off issue? Would be greatly appreciated from the community

adw0rd commented 1 year ago

Provide me username, password and proxy to use (I can't reproduce without it)

https://t.me/m11k4

falexet commented 1 year ago

@adw0rd people'd be more inclined to help if the request is made politely, consider using words "please/thank you". The issue seems to be expanding and it is in everyone's interests to investigate.

The issue is reproduced on a brand new account without proxy. The location seems to be irrelevant as the issue has been reported from different countries.

florifull commented 1 year ago

Same issue here.... started happening yesterday.

It appears there there is a major legitimate issue currently. I am also getting this BadPassword stuff despite using rotating resis... program was working perfectly for last 3 weeks and now getting these issues :(

florifull commented 1 year ago

^^I would like to add that this only happened once I tried logging in with a different account that I did not have a session saved for yet.

But now since there is this issue of BadPassword, I cannot get a successful session since I can't log in to begin with..

codingthegr8t commented 1 year ago

exact same issue! But I may shed some light on the problem > This from browser console > Cookie “sessionid” does not have a proper “SameSite” attribute value. Soon, cookies without the “SameSite” attribute or with an invalid value will be treated as “Lax”. This means that the cookie will no longer be sent in third-party contexts. If your application depends on this cookie being available in such contexts, please add the “SameSite=None“ attribute to it. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite 3 checks Cookie “sessionid” has been rejected for invalid domain. checks So it is indeed instagram being hard to get

wytex commented 1 year ago

Same report here...

`import os from instagrapi import Client

Create a new Client object

cl = Client()

Check if the settings file exists

if os.path.exists('settings.json'):

Load the settings from the file

cl.load_settings('settings.json')

else:

Login to Instagram

cl.login('user', 'psw')

# Save the settings, including the login session, to a file
cl.dump_settings('settings.json')

Get the media ID from the URL

media_id = cl.media_pk_from_url('here_the_url')

Like the post

cl.media_like(media_id)

print("Liked the post!")`

adw0rd commented 1 year ago

@adw0rd people'd be more inclined to help if the request is made politely, consider using words "please/thank you". The issue seems to be expanding and it is in everyone's interests to investigate.

The issue is reproduced on a brand new account without proxy. The location seems to be irrelevant as the issue has been reported from different countries.

Please research the problem yourself and send your PR to help others. For all my hundreds and thousands of accounts, this problem is reproduced only if the password is not correct, or if the IP address has been blocked by Instagram and they write as protection that "BadPassword: The password you entered is incorrect. Please try again."

Thank you very much for your contribution to the research!

MartianDominic commented 1 year ago

@adw0rd could the issue be updated chromium to 115?

jahanideveloper commented 1 year ago

I have the same problem Sometimes it logs into the accounts and sometimes it doesn't log in at all and it says the password is wrong.

niklasdrews commented 1 year ago

Same issue worked for a few months. Restart of the script yield bad password error. Also I can log in normally on the web browser with the same credentials so no IP ban either.

florifull commented 1 year ago

@adw0rd people'd be more inclined to help if the request is made politely, consider using words "please/thank you". The issue seems to be expanding and it is in everyone's interests to investigate. The issue is reproduced on a brand new account without proxy. The location seems to be irrelevant as the issue has been reported from different countries.

Please research the problem yourself and send your PR to help others. For all my hundreds and thousands of accounts, this problem is reproduced only if the password is not correct, or if the IP address has been blocked by Instagram and they write as protection that "BadPassword even with the correct password and login"

Thank you very much for your contribution to the research!

I personally have tried with rotating residential proxies and am also getting this BadPassword error. It worked for weeks and now as of two days ago I am now getting these errors. I don't think its because of any IP address block.

Thanks for your help.

redobsi commented 1 year ago

Hello people. For those with this problem, I still haven't found any fix but I can tell you that it works when you use a brand new account with a good proxy. If you're in a rush like me, look into doing this.