stanvanrooy / instauto

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

KeyError: 'logged_in_user' (Potentially caused by Challenge) #46

Closed nrdt-maker closed 3 years ago

nrdt-maker commented 4 years ago
from instauto import ApiClient
client = ApiClient(user_name=username, password=password)
client.login()

trace:

---------------------------------------------------------------------------
.../python3.8/site-packages/instauto/api/actions/authentication.py in login(self)
     62         # does the actual login
     63         resp = self._request('accounts/login/', Method.POST, data=data2, signed=True)
---> 64         self.state.logged_in_account_data = LoggedInAccountData(**resp.json()['logged_in_user'])
     65 
     66     def _build_initial_headers(self) -> Dict[str, str]:

KeyError: 'logged_in_user'

This might be due to a challenge request (where Instagram asks for a phone/email text message code verification). Could you add this feature to handle that?

Some tips for this: https://github.com/dilame/instagram-private-api/issues/1068#issuecomment-593190908

stanvanrooy commented 4 years ago

Could you send over the debug logging output? Make sure to remove any personal information.

nrdt-maker commented 4 years ago

Here's the full output:

No state provided. Logging in...
Adding job tentatively -- it will be properly scheduled when the scheduler starts
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-001acf9d5b25> in <module>
      3 
      4 client = ApiClient(user_name=username, password=password)
----> 5 client.login()

.../python3.8/site-packages/instauto/api/actions/authentication.py in login(self)
     62         # does the actual login
     63         resp = self._request('accounts/login/', Method.POST, data=data2, signed=True)
---> 64         self.state.logged_in_account_data = LoggedInAccountData(**resp.json()['logged_in_user'])
     65 
     66     def _build_initial_headers(self) -> Dict[str, str]:

KeyError: 'logged_in_user'

username and password are variables containing the correct username and password.

stanvanrooy commented 4 years ago

Could you add something like this to the script, so all debug calls to the logger are outputted as well? I'm on my phone so not sure if this will actually work, but should be pretty simple.

import logging 
logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG)
nrdt-maker commented 4 years ago

Thanks for following up! Here's the logs:

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): i.instagram.com:443
DEBUG:urllib3.connectionpool:https://i.instagram.com:443 "GET /api/v1/zr/token/result/?device_id=android-1f2b4eba8857b104&token_hash=&custom_device_id=c2f5bb14-1f2b-4eba-8857-b104163078e8&fetch_reason=token_expired HTTP/1.1" 200 203
DEBUG:instauto.api.actions.request:Sent request to https://i.instagram.com/api/v1/zr/token/result/?device_id=android-1f2b4eba8857b104&token_hash=&custom_device_id=c2f5bb14-1f2b-4eba-8857-b104163078e8&fetch_reason=token_expired, method: GET with data: 
 {}
DEBUG:instauto.api.actions.request:******************** START REQUEST ********************
METHOD: GET
URL: https://i.instagram.com/api/v1/zr/token/result/?device_id=android-1f2b4eba8857b104&token_hash=&custom_device_id=c2f5bb14-1f2b-4eba-8857-b104163078e8&fetch_reason=token_expired
DATA: {}
HEADERS: {'x-ig-connection-type': 'WIFI', 'x-ig-capabilities': '3brTvw8=', 'x-ig-app-id': '567067343352427', 'user-agent': 'Instagram 148.0.0.33.121 Android (29/10; 560dpi; 1440x2891; samsung; SM-973F; SM-973F; exynos9820; nl_NL; 227298996)', 'accept-language': 'nl_NL', 'accept-encoding': 'gzip, deflate', 'x-fb-http-engine': 'Liger', 'x-ig-connection-speed': '2925kbps', 'x-ig-bandwidth-speed-kbps': '2964.364', 'x-ig-bandwidth-totalbytes-b': '0', 'x-ig-bandwidth-totaltime-ms': '0', 'x-ig-www-claim': '0'}
RESPONSE: b'{"token": {"carrier_name": "", "carrier_id": 0, "ttl": 72000, "features": [], "request_time": 1600601967, "token_hash": "", "rewrite_rules": [], "enabled_wallet_defs_keys": [], "deadline": "", "zero_cms_fetch_interval_seconds": 86400, "carrier_signal_config": []}, "status": "ok"}'
******************** END REQUEST ********************
DEBUG:urllib3.connectionpool:https://i.instagram.com:443 "POST /api/v1/qe/sync/ HTTP/1.1" 200 616
DEBUG:instauto.api.actions.request:Sent request to https://i.instagram.com/api/v1/qe/sync/, method: POST with data: 
 {'_csrftoken': 'GCKE6j5bXd3lqo7bMK4tryR7Ed0WGdfW', 'id': 'c2f5bb14-1f2b-4eba-8857-b104163078e8', 'sever_config_retrieval': '1', 'experiments': 'ig_android_device_detection_info_upload,ig_android_gmail_oauth_in_reg,ig_android_account_linking_upsell_universe,ig_android_direct_main_tab_universe_v2,ig_android_sign_in_help_only_one_account_family_universe,ig_android_sms_retriever_backtest_universe,ig_android_vc_interop_use_test_igid_universe,ig_android_direct_add_direct_to_android_native_photo_share_sheet,ig_growth_android_profile_pic_prefill_with_fb_pic_2,ig_account_identity_logged_out_signals_global_holdout_universe,ig_android_notification_unpack_universe,ig_android_quickcapture_keep_screen_on,ig_android_device_based_country_verification,ig_android_login_identifier_fuzzy_match,ig_android_reg_modularization_universe,ig_android_video_render_codec_low_memory_gc,ig_android_device_verification_separate_endpoint,ig_android_email_fuzzy_matching_universe,ig_android_suma_landing_page,ig_android_smartlock_hints_universe,ig_android_video_ffmpegutil_pts_fix,ig_android_multi_tap_login_new,ig_android_retry_create_account_universe,ig_android_caption_typeahead_fix_on_o_universe,ig_android_enable_keyboardlistener_redesign,ig_android_reg_nux_headers_cleanup_universe,ig_android_get_cookie_with_concurrent_session_universe,ig_android_nux_add_email_device,ig_android_device_info_foreground_reporting,ig_android_shortcuts_2019,ig_android_device_verification_fb_signup,ig_android_passwordless_account_password_creation_universe,ig_android_black_out_toggle_universe,ig_video_debug_overlay,ig_android_ask_for_permissions_on_reg,ig_assisted_login_universe,ig_android_security_intent_switchoff,ig_android_recovery_one_tap_holdout_universe,ig_android_sim_info_upload,ig_android_mobile_http_flow_device_universe,ig_android_fb_account_linking_sampling_freq_universe,ig_android_access_flow_prefill'}
DEBUG:instauto.api.actions.request:******************** START REQUEST ********************
METHOD: POST
URL: https://i.instagram.com/api/v1/qe/sync/
DATA: {'_csrftoken': 'GCKE6j5bXd3lqo7bMK4tryR7Ed0WGdfW', 'id': 'c2f5bb14-1f2b-4eba-8857-b104163078e8', 'sever_config_retrieval': '1', 'experiments': 'ig_android_device_detection_info_upload,ig_android_gmail_oauth_in_reg,ig_android_account_linking_upsell_universe,ig_android_direct_main_tab_universe_v2,ig_android_sign_in_help_only_one_account_family_universe,ig_android_sms_retriever_backtest_universe,ig_android_vc_interop_use_test_igid_universe,ig_android_direct_add_direct_to_android_native_photo_share_sheet,ig_growth_android_profile_pic_prefill_with_fb_pic_2,ig_account_identity_logged_out_signals_global_holdout_universe,ig_android_notification_unpack_universe,ig_android_quickcapture_keep_screen_on,ig_android_device_based_country_verification,ig_android_login_identifier_fuzzy_match,ig_android_reg_modularization_universe,ig_android_video_render_codec_low_memory_gc,ig_android_device_verification_separate_endpoint,ig_android_email_fuzzy_matching_universe,ig_android_suma_landing_page,ig_android_smartlock_hints_universe,ig_android_video_ffmpegutil_pts_fix,ig_android_multi_tap_login_new,ig_android_retry_create_account_universe,ig_android_caption_typeahead_fix_on_o_universe,ig_android_enable_keyboardlistener_redesign,ig_android_reg_nux_headers_cleanup_universe,ig_android_get_cookie_with_concurrent_session_universe,ig_android_nux_add_email_device,ig_android_device_info_foreground_reporting,ig_android_shortcuts_2019,ig_android_device_verification_fb_signup,ig_android_passwordless_account_password_creation_universe,ig_android_black_out_toggle_universe,ig_video_debug_overlay,ig_android_ask_for_permissions_on_reg,ig_assisted_login_universe,ig_android_security_intent_switchoff,ig_android_recovery_one_tap_holdout_universe,ig_android_sim_info_upload,ig_android_mobile_http_flow_device_universe,ig_android_fb_account_linking_sampling_freq_universe,ig_android_access_flow_prefill'}
HEADERS: {'x-cm-bandwidth-kbps': '-1.000', 'x-cm-latency': '-1.000', 'x-ads-opt-out': '0', 'x-ig-app-locale': 'nl_NL', 'x-ig-app-startup-country': 'NL', 'x-ig-device-locale': 'nl_NL', 'x-ig-mapped-locale': 'nl_NL', 'x-ig-connection-speed': '3421kbps', 'x-ig-bandwidth-speed-kbps': '3826.188', 'x-ig-bandwidth-totalbytes-b': '0', 'x-ig-bandwidth-totaltime-ms': '0', 'x-ig-www-claim': '0', 'x-ig-device-id': 'c2f5bb14-1f2b-4eba-8857-b104163078e8', 'x-ig-android-id': 'android-1f2b4eba8857b104', 'x-ig-connection-type': 'WIFI', 'x-ig-capabilities': '3brTvw8=', 'x-ig-app-id': '567067343352427', 'user-agent': 'Instagram 148.0.0.33.121 Android (29/10; 560dpi; 1440x2891; samsung; SM-973F; SM-973F; exynos9820; nl_NL; 227298996)', 'accept-language': 'nl_NL, en_US', 'x-mid': 'X2c_bwABAAGj9NiR-B4-r4bVqTc_', 'ig-u-rur': 'VLL', 'accept-encoding': 'gzip', 'x-fb-http-engine': 'Liger', 'authorization': 'Bearer IGT:2:', 'connection': 'close', 'x-pigeon-session-id': 'b2614b72-fa95-461b-9ac1-66cafe82dc75', 'x-pigeon-rawclienttime': '1600601967.68', 'x-bloks-version-id': '5da07fc1b20eb4c7d1b2e6146ee5f197072cbbd193d2d1eb3bb4e825d3c39e28', 'x-bloks-is-layout-rtl': 'False', 'host': 'i.instagram.com', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
RESPONSE: b'{"experiments": [{"name": "ig_android_gmail_oauth_in_reg", "group": "rollout_1201", "additional_params": [], "params": [{"name": "try_background_confirm", "value": "true"}]}, {"name": "ig_android_account_linking_upsell_universe", "group": "test", "additional_params": [], "params": [{"name": "logout_impression_limit", "value": "2"}]}, {"name": "ig_android_direct_add_direct_to_android_native_photo_share_sheet", "group": "test", "additional_params": [], "params": [{"name": "is_enabled", "value": "true"}]}, {"name": "ig_android_quickcapture_keep_screen_on", "group": "test", "additional_params": [], "params": [{"name": "keep_screen_on_enabled", "value": "true"}]}, {"name": "ig_android_login_identifier_fuzzy_match", "group": "edit2", "additional_params": [], "params": [{"name": "enabled", "value": "true"}, {"name": "cost", "value": "2"}]}, {"name": "ig_android_video_render_codec_low_memory_gc", "group": "control", "additional_params": [], "params": [{"name": "gc_before_codec_init", "value": "false"}]}, {"name": "ig_android_suma_landing_page", "group": "var1_skip_value_props", "additional_params": [], "params": [{"name": "show_title", "value": "false"}, {"name": "show_generic_icon", "value": "false"}, {"name": "skip_value_prop", "value": "false"}]}, {"name": "ig_android_video_ffmpegutil_pts_fix", "group": "test", "additional_params": [], "params": [{"name": "retry_count", "value": "5"}]}, {"name": "ig_android_multi_tap_login_new", "group": "test", "additional_params": [], "params": [{"name": "enabled", "value": "true"}, {"name": "show_logged_out_only", "value": "true"}]}, {"name": "ig_android_get_cookie_with_concurrent_session_universe", "group": "test", "additional_params": [], "params": [{"name": "is_enabled", "value": "true"}]}, {"name": "ig_android_passwordless_account_password_creation_universe", "group": "test_one_tap_check_box_shown", "additional_params": [], "params": [{"name": "show_save_password_checkbox", "value": "true"}, {"name": "upsell_for_mac_flow", "value": "true"}]}, {"name": "ig_android_security_intent_switchoff", "group": "allusers", "additional_params": [], "params": [{"name": "switch_offs", "value": ""}]}, {"name": "ig_android_sim_info_upload", "group": "test", "additional_params": [], "params": [{"name": "enable_upload", "value": "true"}]}, {"name": "ig_android_fb_account_linking_sampling_freq_universe", "group": "control", "additional_params": [], "params": [{"name": "freq", "value": "100"}]}], "status": "ok"}'
******************** END REQUEST ********************
DEBUG:urllib3.connectionpool:Resetting dropped connection: i.instagram.com
DEBUG:urllib3.connectionpool:https://i.instagram.com:443 "POST /api/v1/accounts/login/ HTTP/1.1" 400 441
DEBUG:instauto.api.actions.request:Sent request to https://i.instagram.com/api/v1/accounts/login/, method: POST with data: 
 {'ig_sig_key_version': '4', 'signed_body': 'SIGNATURE.{"jazoest": "22363", "phone_id": "6a5b09e7-2f0d-4728-9c1d-c0547ab13d22", "device_id": "android-1f2b4eba8857b104", "guid": "6fdb09e4-c116-405f-83da-8419702a943f", "_csrftoken": "GCKE6j5bXd3lqo7bMK4tryR7Ed0WGdfW", "adid": "f68b6197-bd37-4bf6-b450-90f5db9c5ab4", "google_tokens": "[]", "username": "xxx", "country_codes": "[{\\"country_code\\":\\"31\\",\\"source\\": \\"default\\"}]", "enc_password": "#PWD_INSTAGRAM:xxx", "login_attempt_count": "0"}'}
DEBUG:instauto.api.actions.request:******************** START REQUEST ********************
METHOD: POST
URL: https://i.instagram.com/api/v1/accounts/login/
DATA: {'ig_sig_key_version': '4', 'signed_body': 'SIGNATURE.{"jazoest": "22363", "phone_id": "6a5b09e7-2f0d-4728-9c1d-c0547ab13d22", "device_id": "android-1f2b4eba8857b104", "guid": "6fdb09e4-c116-405f-83da-8419702a943f", "_csrftoken": "GCKE6j5bXd3lqo7bMK4tryR7Ed0WGdfW", "adid": "f68b6197-bd37-4bf6-b450-90f5db9c5ab4", "google_tokens": "[]", "username": "xxx", "country_codes": "[{\\"country_code\\":\\"31\\",\\"source\\": \\"default\\"}]", "enc_password": "#PWD_INSTAGRAM:xxx", "login_attempt_count": "0"}'}
HEADERS: {'x-cm-bandwidth-kbps': '-1.000', 'x-cm-latency': '-1.000', 'x-ads-opt-out': '0', 'x-ig-app-locale': 'nl_NL', 'x-ig-app-startup-country': 'NL', 'x-ig-device-locale': 'nl_NL', 'x-ig-mapped-locale': 'nl_NL', 'x-ig-connection-speed': '2228kbps', 'x-ig-bandwidth-speed-kbps': '3983.161', 'x-ig-bandwidth-totalbytes-b': '0', 'x-ig-bandwidth-totaltime-ms': '0', 'x-ig-www-claim': '0', 'x-ig-device-id': 'c2f5bb14-1f2b-4eba-8857-b104163078e8', 'x-ig-android-id': 'android-1f2b4eba8857b104', 'x-ig-connection-type': 'WIFI', 'x-ig-capabilities': '3brTvw8=', 'x-ig-app-id': '567067343352427', 'user-agent': 'Instagram 148.0.0.33.121 Android (29/10; 560dpi; 1440x2891; samsung; SM-973F; SM-973F; exynos9820; nl_NL; 227298996)', 'accept-language': 'nl_NL, en_US', 'x-mid': 'X2c_bwABAAGj9NiR-B4-r4bVqTc_', 'ig-u-rur': 'VLL', 'accept-encoding': 'gzip', 'x-fb-http-engine': 'Liger', 'authorization': 'Bearer IGT:2:', 'connection': 'close', 'x-pigeon-session-id': 'b2614b72-fa95-461b-9ac1-66cafe82dc75', 'x-pigeon-rawclienttime': '1600601967.826', 'x-bloks-version-id': '5da07fc1b20eb4c7d1b2e6146ee5f197072cbbd193d2d1eb3bb4e825d3c39e28', 'x-bloks-is-layout-rtl': 'False', 'host': 'i.instagram.com', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
RESPONSE: b'{"message": "challenge_required", "challenge": {"url": "https://i.instagram.com/challenge/<userid>/iyfKnZ4VTY/", "api_path": "/challenge/<userid>/iyfKnZ4VTY/", "hide_webview_header": true, "lock": true, "logout": false, "native_flow": true, "challenge_context": "{\\"step_name\\": \\"\\", \\"nonce_code\\": \\"iyfKnZ4VTY\\", \\"user_id\\": <userid>, \\"is_stateless\\": false}"}, "status": "fail", "error_type": "checkpoint_challenge_required"}'
******************** END REQUEST ********************
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.8/site-packages/instauto/api/actions/authentication.py", line 64, in login
    self.state.logged_in_account_data = LoggedInAccountData(**resp.json()['logged_in_user'])
KeyError: 'logged_in_user'
stanvanrooy commented 4 years ago

Okay, it is indeed caused by a challenge. I've started work on a new feature that will handle checkpoints, but I'm not sure yet when it will be tested and ready.

stanvanrooy commented 4 years ago

@nrdt-maker I've made a start in the 46ChallengeRequired branch, but I can't get Instagram to trigger the challenge, which means I can't test to see how the Instagram API responds to my requests sent. If it works as it's supposed to, then it should trigger a phone verification code being sent, but again, I have no way of testing this.

If you'd be willing to run the version in that branch and upload the responses, that would be a massive help.

You can pull that specific branch to your machine and then install it in a virtualenv with either pip install -e . or python setup.py install. Now with this version of instauto, it should output two files if you run your code:

  1. response.pickle, which contains the response to the 'request challenge information' API call
  2. 'respones1.pickle`, which contains the response to the 'request phone verification code API call'.

Besides possibly your phone number, these do not contain sensitive information. If you'd prefer sending them over email rather then uploading them here, you can reach me at stan@rooy.dev

stanvanrooy commented 3 years ago

@nrdt-maker Let me know what you think.

nrdt-maker commented 3 years ago

Hey, thanks for making the branch. Sorry I'm a bit slow to respond. I think I was able to trigger the challenge because the IP address changed (using a server IP vs. home IP). Perhaps you can try that? Would be faster for you if you can get the challenge yourself. I also don't feel comfortable sharing too much of the data since I'm using my personal insta.

stanvanrooy commented 3 years ago

No problem, totally understandable. I tried that, but that only resulted in the "was this you?" checkpoint.

I'll figure something out. If you watch this issue, you'll be notified when it is implemented.

stanvanrooy commented 3 years ago

No problem, totally understandable. I tried that, but that only resulted in the "was this you?" checkpoint.

I'll figure something out. If you watch this issue, you'll be notified when it is implemented.

skiesx commented 3 years ago

HI) i have the same problem(

stanvanrooy commented 3 years ago

Please see the commen I made above, and if that is something you can do. Without those requests, I can't implement a fix.

zecloud commented 3 years ago

HI, I have the challenge activated and i tried the code the branch 46Challengerequired but it didn't created the pickle files. It throw another exception

File "/home/vsonline/workspace/instauto/chal/lib/python3.8/site-packages/instauto/api/actions/authentication.py", line 64, in login resp = self._request('accounts/login/', Method.POST, data=data2, signed=True) File "/home/vsonline/workspace/instauto/chal/lib/python3.8/site-packages/instauto/api/actions/request.py", line 213, in _request self._check_response_for_errors(resp) File "/home/vsonline/workspace/instauto/chal/lib/python3.8/site-packages/instauto/api/actions/request.py", line 239, in _check_response_for_errors eh = self._handle_challenge(resp) File "/home/vsonline/workspace/instauto/chal/lib/python3.8/site-packages/instauto/api/actions/challenge.py", line 28, in _handle_challenge resp = self._request(endpoint=resp_data['api_path'], KeyError: 'api_path'

stanvanrooy commented 3 years ago

Could you add an additional logging statement that logs the contents of resp_data?

I'll try and look into this as soon as I have time.

CombatCode commented 3 years ago

Please upgrade 46ChallengeRequired to 0.0.15, now I get everytime that challanger screen

zecloud commented 3 years ago

After changing challenge.py code to the following resp_data['challenge']['api_path'][1:] i have this response data i cleared my personal data in the response :

{ "step_name": "select_verify_method", "step_data": { "choice": "0", "fb_access_token": "None", "big_blue_token": "None", "google_oauth_token": "true", "vetted_device": "None", "phone_number": "", "email": "" }, "flow_render_type": 3, "bloks_action": "com.instagram.challenge.navigation.take_challenge", "nonce_code": "", "user_id": , "challenge_context": "{\"step_name\": \"select_verify_method\", \"nonce_code\": \"\", \"user_id\": , \"is_stateless\": false}", "status": "ok" }'

stanvanrooy commented 3 years ago

Thank you! Did it sent 2 requests? Or just this one?

zecloud commented 3 years ago

I Succeed to pass the challenge following the post from https://github.com/dilame/instagram-private-api/issues/1068#issuecomment-593190908

I can't make you a pull request but here is my quick and dirty code for the challenge.py file.

import requests import json import logging import pickle

from instauto.api.structs import DeviceProfile, IGProfile, State, Method from instauto.api.exceptions import BadResponse from instauto.api.actions.stubs import _request from ..structs import Method, State, IGProfile, LoggedInAccountData logging.basicConfig()

logger = logging.getLogger(name) logger.setLevel(logging.DEBUG)

class ChallengeMixin: ig_profile: IGProfile device_profile: DeviceProfile state: State _session: requests.Session _request: _request

def _handle_challenge(self, resp: requests.Response) -> bool:
    security_code = None
    resp_data = resp.json()
    if resp_data['message'] not in ('challenge_required', 'checkpoint_required'):
        raise BadResponse("Challenge required, but no URL provided.")
    apichallpath=resp_data['challenge']['api_path'][1:]
    resp = self._request(endpoint=apichallpath,
                         method=Method.GET,
                         query={
                             "guid": self.state.uuid,
                             "device_id": self.state.device_id
                         })
    with open('./response.pickle', 'wb+') as f:
        pickle.dump(resp, f)

    resp_data = resp.json()
    bloks_action = resp_data['bloks_action']
    # Handle unknown device challenge
    if bloks_action == 'com.instagram.challenge.navigation.take_challenge':
        resp = self._request(
            endpoint=apichallpath, method=Method.POST, data = {
                "choice": 0,  # 0 = this was me, 1 = this wasn't me,
                "_csrftoken": self._session.cookies['csrftoken'],
                "_uuid": self.state.uuid,
                "bloks_versioning_id": self.state.bloks_version_id,
                "post": 1
            }
        )
        with open('./response1.pickle', 'wb+') as f:
            pickle.dump(resp, f)
        resp_data = resp.json()
        if security_code is None:
            security_code = input("Type the security code here: ")
        resp = self._request(
            endpoint=apichallpath, method=Method.POST, data = {
                "_csrftoken": self._session.cookies['csrftoken'],
                "_uuid": self.state.uuid,
                "bloks_versioning_id": self.state.bloks_version_id,
                "post": 1,
                "security_code":security_code
            }
        )
        resp_data = resp.json()
        self.state.logged_in_account_data = LoggedInAccountData(resp_data['logged_in_user'])
        if resp_data['status'] == "ok":
            return True

    return False
stanvanrooy commented 3 years ago

Thank you, works perfectly! Could you still upload the responses?

There are multiple types of challenges, we want to respond accordingly. Your example works, but it just throws both responses at the API.

Ideally, we want to distinguish the simple challenge from the verification pin challenge and respond accordingly.

CombatCode commented 3 years ago

@stanvanrooy can you please upgrade this branch to current master (to be able to run it with python 3.6) and apply changes from zecould ? I will test it

zecloud commented 3 years ago

To avoid the exception throwed by the two responses i changed the last lines of login method in authentication py in

resp = self._request('accounts/login/', Method.POST, data=data2, signed=True)
    parsed =resp.json()
    if('logged_in_user' in resp.json()):
        self.state.logged_in_account_data = LoggedInAccountData(**resp.json()['logged_in_user'])

the last step is something like that { "step_name": "verify_code", "step_data": { "security_code": "", "sms_resend_delay": 60, "phone_number_preview": "", "resend_delay": 60, "contact_point": "", "form_type": "phone_number", "phone_number_formatted": "", "phone_number": "" }, "flow_render_type": 3, "bloks_action": "com.instagram.challenge.navigation.take_challenge", "nonce_code": "", "user_id": , "challenge_context": "{\"step_name\": \"verify_code\", \"nonce_code\": \"\", \"user_id\": , \"is_stateless\": false}", "status": "ok" } after that it's the same response as login.

you have the content of the responses in this comment the json contains the same things as the std class in his comment https://github.com/dilame/instagram-private-api/issues/1068#issuecomment-581360239

I had my bot account on temporary lockdown so i'll play a little bit more safe with this account. Thanks for your great work on this project.

stanvanrooy commented 3 years ago

Pin verifications are fixed in the latest release.