stanvanrooy / instauto

Simple to use wrapper around the private Instagram API, written in Python.
https://instauto.readthedocs.io
MIT License
105 stars 24 forks source link

Accounts with two-factor authentication turned on can't be logged in. #143

Closed hmdz105 closed 3 years ago

hmdz105 commented 3 years ago

Describe the bug When 2FA is turned on in an instagram account, the app faces an error when trying to log in:

To Reproduce Steps to reproduce the behavior: Run the following code

import os

from instauto.api.client import ApiClient
from instauto.api import structs as st
from instauto.api.actions import post as ps

if os.path.isfile('./.instauto.save'):
    client = ApiClient.initiate_from_file('./.instauto.save')
else:
    client = ApiClient(user_name="username", password="password")
    client.login()
    client.save_to_disk('./.instauto.save')

Assuming the app has no previous saved session, the new login fails with this error:

Traceback (most recent call last):
  File "G:\DB\Dropbox\instagramPrjct\Initial tests-v0.2\InstagramUploader.py", line 38, in <module>
    client.login()
  File "C:\Users\Hamed\AppData\Roaming\Python\Python39\site-packages\instauto\api\actions\authentication.py", line 64, in login
    resp = self._request('accounts/login/', Method.POST, data=data2, signed=True)
  File "C:\Users\Hamed\AppData\Roaming\Python\Python39\site-packages\instauto\api\actions\request.py", line 233, in _request
    self._check_response_for_errors(resp)
  File "C:\Users\Hamed\AppData\Roaming\Python\Python39\site-packages\instauto\api\actions\request.py", line 274, in _check_response_for_errors
    raise BadResponse("Received a non-200 response from Instagram")
instauto.api.exceptions.BadResponse: Received a non-200 response from Instagram

Expected behavior The console should ask for the 2FA code. After manual entry, the log in should succeed and the bot continue working.

Additional context I used another library called "instabot" and it asked for 2FA then logged in. Unfortunately the library is outdated and no longer maintained, and many of its endpoints no longer work.

stanvanrooy commented 3 years ago

You can now either pass in a _2fa_function argument to the constructor of ApiClient, or just type the code in to the terminal.

The _2fa_function should be a callable that receives the username as input and returns the 2fa code as output.

hmdz105 commented 3 years ago

Excellent job! Thanks for the quick fix!

stanvanrooy commented 3 years ago

Let me know if there's anything else missing from instauto :)

Hamed schreef op 2021-02-18 09:51:

Excellent job! Thanks for the quick fix!

-- You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub [1], or unsubscribe [2].

Links:

[1] https://github.com/stanvanrooy/instauto/issues/143#issuecomment-781185866 [2] https://github.com/notifications/unsubscribe-auth/AL2ES6KHNLC7SRUBFCJM3L3S7TIJZANCNFSM4XVDQZEQ

hmdz105 commented 3 years ago

I can't still find a way to upload videos. Sending videos to posts, stories and also in carousel format would be very handy.