[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.
I can't reproduce it, figure it out yourself and send us your fixes as PR if the bug really exists
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 got the same error.
The problem might be in .env. Instead, try hardcoded approach like this:
username = "YOUR USERNAME HERE"
password = "YOUR PASSWORD HERE"
Where is .env?
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 ?
@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?
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.
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()
@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 🥲
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
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. 🥲
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.
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?
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!
So this morning the issue is back. Didn't figure out way to resolve it yet.
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
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
It is possible that Instagram now blocks accounts like this. Try changing your proxy, you should try
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: @.***>
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 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: @.***>
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)?
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: @.***>
@falexet if this header is within instagrapi, yes, I'm using default. Is there a public method to change it?
@ManeFunction I personally have a venv, and went into the auth code part. You may explore that endpoint through github library locally
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 :(
@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.
@falexet I'm using cl.set_device(Dict), is it ok?
Anybody managed to login with instagrapi ?