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

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.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 6
  • Comments: 107 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@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.

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 ?

I think I’ve found a way to fix it, but I need more testing. If everything works I’ll write how to fix it soon.

On 8 Oct 2023, at 3:37 PM, dx @.***> wrote:

I know it’s a bit old issue but has anyone facing it yet? I was using the script to just post stories on my profile using my home ip address for a month. But today i got BadPassword exception. I tried to login using 2FA as described here and got challenge_required. Anyone has any solution?

I don’t have solution, but I’m facing the same issue. My code has been working for 3 months posting daily around 60 photos and 60 stories on 20 different accounts. Yesterday I’ve got my first BadPassword exception and I can’t find a way to fix it.

Yeah, same. I started facing the issue yesterday after 1 month using the script.

— Reply to this email directly, view it on GitHub https://github.com/subzeroid/instagrapi/issues/1498#issuecomment-1752030689, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH643PV4TCIMCC6IBKJKFX3X6KUATAVCNFSM6AAAAAA25FRRNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJSGAZTANRYHE. You are receiving this because you commented.

I found a workaround by enabling 2FA and using pyotp with the generated key from Insta to get the verification code programmatically.

import pyotp
insta_username = Config.INSTAGRAM_USERNAME
insta_password = Config.INSTAGRAM_PASSWD
secret= Config.INSTAGRAM_SECRET

totp = pyotp.TOTP( secret)
verification_code = totp.now() 

cl = Client( logger=log)
cl.login(insta_username, insta_password) # <= return False
cl.login(insta_username, insta_password, verification_code=verification_code) # <= Return True

I got the same error.

id like to add that i just got it working, all i did was change my password. Anyone else have luck with this?

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.

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. 🥲

Same problem here. Can log into IG in my browser and same IP (so password is correct and there’s no IP ban), but instagrapi is throwing me a badpassword error. AS others, I suspect is the device id that’s being blocked.

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

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.

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!

verification_code=verification_code

I’ve been able to use this method (2FA and pyotp) to login again and upload stories and post via instagrapi. I didn’t use proxies. I’ll report if this breaks again.

I tried everything here (I am in the boat of those having the issue).

Investigating for hours I can state that my ip isn’t blocked, but somehow my “script” is. Well, no my script, but anything not which is not my phone or my browser (chrome and iPhone). Login from safari will not recognise the password.

I am under the impression that instagram has somehow trusted under the hood those two clients while blacklisted / blocked everything else…

Hello everyone, this worked for me: using a residential Proxy and Instagrapi Sessions Hope it helps:)

it was working ob, but im getting this error since yesterday:

The password you entered is incorrect. Please try again. 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:

but the passaword is ok. i can login at chrome and my iphone with the password

@antoinep303 tried your solution… it has a potential, but can’t manage to work it myself. Every time I’m trying to log in with 2FA enabled through the script, I’m getting “challenge_required” error and when I’m opening IG from app or web next time, it FORCE me to change a password. So, still no luck here 😦

UPD: Tried elinks and w3m terminal browsers in hope of opening an instagram on target machine and add it to the trusted devices that way, but this programs can’t handle even a login page of instagram.

Hello friends

Has your problem been solved by setting a proxy?

No. I am using residential rotating proxies and it doesn’t help at all…

my only error now is ClipNotUpload. It used to work and now it doesn’t. I don’t have a proxy however I never did beforehand and it worked.

Adw0rd is suggesting I try different clips, however my code does this already as it picks a new media every time it is run and never posts the same clip or pic etc.

I know instagram is probably cracking down on bots but how can we work around this? I’ve seen talks about headers and ‘samesite’ attributes. Has anyone been able to upload clips lately?

@adw0rd was able to login and post with my tester account via resi proxy. I am going to test for myself, it may be because of me not running on Instagrapi latest version, not sure how he was able to do this so easily.

He used my resi proxy to create a client and then logged in with that proxy.

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.

@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!

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 😦

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

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

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?

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

  • Was logged in Safari for couple of weeks
  • Tried to execute code to log in using login/password and got ‘invalid password’
  • Logged out from Instagram in Safari and was able to log in again using the same login/password
  • Log in using code still didn’t work
  • Tried to log in from Chrome browser. Wasn’t able to - got the same ‘invalid password, please double check’ error in UI.
  • Logged out from Instagram in Safari and was able to log in again using the same login/password
  • Changed account password from Safari in account center to a shorter password (not sure if it matters though)
  • Was able to log in into Instagram from both Chrome and code.

Hope this helps.

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 ?