subzeroid / instagrapi

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

[BUG] "login_required" error against two factor authentication #362

Closed mvx20 closed 1 year ago

mvx20 commented 3 years ago

Describe the bug "login_required" error against two factor authentication

To Reproduce

cli = Client()
code = cli.totp_generate_code("MYSEED")
cli.login(username="USERNAME",password="PASSWD",verification_code=str(code))

Traceback

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 269, in _send_private_request
    response.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 943, 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/reels_tray/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/PycharmProjects/MVRL/zoneSocial/pyot.py", line 9, in <module>
    cli.login(username="USERNAME",password="PASSWD",verification_code=str(code))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 408, in login
    self.login_flow()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 166, in login_flow
    check_flow.append(self.get_reels_tray_feed("cold_start"))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 243, in get_reels_tray_feed
    return self.private_request("feed/reels_tray/", data)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 414, in private_request
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 401, 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 294, in _send_private_request
    raise LoginRequired(response=e.response, **last_json)
instagrapi.exceptions.LoginRequired: login_required

Expected behavior seamless login

Desktop (please complete the following information):

Additional context I'm sorry for my bad english

mvx20 commented 3 years ago

Error info update

Attached is the error I encountered as of the moment.

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 270, in _send_private_request
    response.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 943, 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 "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 387, 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 415, in private_request
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 402, 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 320, in _send_private_request
    raise TwoFactorRequired(**last_json)
instagrapi.exceptions.TwoFactorRequired: Two-factor authentication required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 270, in _send_private_request
    response.raise_for_status()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 943, 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/two_factor_login/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/user/PycharmProjects/MVRL/zoneSocial/pyot.py", line 9, in <module>
    cli.login(username="USERNAME",password="PASSWORD",verification_code=str(str(code)))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/auth.py", line 409, in login
    logged = self.private_request("accounts/two_factor_login/", data, login=True)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 415, in private_request
    raise e
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/instagrapi/mixins/private.py", line 402, 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 326, in _send_private_request
    raise UnknownError(**last_json)
instagrapi.exceptions.UnknownError: This code is no longer valid. Please request a new one.