From c9c0d113a5beaedfa807c46f4c452c3981062780 Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Tue, 9 Apr 2024 22:38:01 +0330 Subject: [PATCH 01/10] Update user.py __a=1&__d=dis no longer work , replaced with web_profile_info --- instagrapi/mixins/user.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index 30be7cd8..bf9e1a7f 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -141,7 +141,10 @@ def user_info_by_username_gql(self, username: str) -> User: An object of User type """ username = str(username).lower() - return extract_user_gql(self.public_a1_request(f"/{username!s}/")["user"]) + headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} + #return extract_user_gql(requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user']) + return requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user'] + def user_info_by_username_v1(self, username: str) -> User: """ From fe59f3e63fa50119beec077cefbac2c29f2c636c Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Wed, 10 Apr 2024 14:38:11 +0330 Subject: [PATCH 02/10] Update user.py remove commented line --- instagrapi/mixins/user.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index bf9e1a7f..8bd12931 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -142,9 +142,8 @@ def user_info_by_username_gql(self, username: str) -> User: """ username = str(username).lower() headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} - #return extract_user_gql(requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user']) - return requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user'] - + return extract_user_gql(requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user']) + def user_info_by_username_v1(self, username: str) -> User: """ From e139fbf7241857a91add451cc5f36796653e21b0 Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Wed, 10 Apr 2024 14:44:54 +0330 Subject: [PATCH 03/10] Update user.py --- instagrapi/mixins/user.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index 8bd12931..624f47a6 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -142,8 +142,7 @@ def user_info_by_username_gql(self, username: str) -> User: """ username = str(username).lower() headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} - return extract_user_gql(requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user']) - + return extract_user_gql(requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user']) def user_info_by_username_v1(self, username: str) -> User: """ From 738f059c5256f591cff3b66ca1f97190a10cc4f3 Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Thu, 11 Apr 2024 13:11:38 +0330 Subject: [PATCH 04/10] Update user.py added self.public_request for better error handling. --- instagrapi/mixins/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index 624f47a6..9d63d0d4 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -142,7 +142,7 @@ def user_info_by_username_gql(self, username: str) -> User: """ username = str(username).lower() headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} - return extract_user_gql(requests.get(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers, verify=False, proxies = {'http' : self.proxy, 'https':self.proxy}).json()['data']['user']) + return extract_user_gql(json.loads(self.public_request(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers))['data']['user']) def user_info_by_username_v1(self, username: str) -> User: """ From dd085e7c529976fcafc1627ffb293a5a20df6cf2 Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:10:58 +0330 Subject: [PATCH 05/10] Update user.py user info gql fix + implemented in public_request + avoid headers to be updated --- instagrapi/mixins/user.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index 9d63d0d4..f782a7c7 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -140,9 +140,11 @@ def user_info_by_username_gql(self, username: str) -> User: User An object of User type """ - username = str(username).lower() - headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} - return extract_user_gql(json.loads(self.public_request(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=headers))['data']['user']) + + temporary_public_headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} + update_headers = False + data = extract_user_gql(json.loads(self.public_request(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=temporary_public_headers))['data']['user'], update_headers=update_headers) + return data def user_info_by_username_v1(self, username: str) -> User: """ From a0f93ec7bc752dd8b9d6ab83ca7d6d0e837f9136 Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:14:39 +0330 Subject: [PATCH 06/10] Update public.py user info gql fix + implemented in public_request + avoid headers to be updated --- instagrapi/mixins/public.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/instagrapi/mixins/public.py b/instagrapi/mixins/public.py index 53f66cf7..63a23a04 100644 --- a/instagrapi/mixins/public.py +++ b/instagrapi/mixins/public.py @@ -80,6 +80,7 @@ def public_request( data=None, params=None, headers=None, + update_headers=None return_json=False, retries_count=3, retries_timeout=2, @@ -96,7 +97,7 @@ def public_request( try: if self.delay_range: random_delay(delay_range=self.delay_range) - return self._send_public_request(url, **kwargs) + return self._send_public_request(url, update_headers=update_headers, **kwargs) except ( ClientLoginRequired, ClientNotFoundError, @@ -123,11 +124,14 @@ def public_request( continue def _send_public_request( - self, url, data=None, params=None, headers=None, return_json=False, stream=None, timeout=None + self, url, data=None, params=None, headers=None, return_json=False, stream=None, timeout=None, update_headers=None ): self.public_requests_count += 1 if headers: - self.public.headers.update(headers) + if update_headers in [None, True] : + self.public.headers.update(headers) + elif update_headers == False : + pass if self.last_response_ts and (time.time() - self.last_response_ts) < 1.0: time.sleep(1.0) if self.request_timeout: From d2d9aa16f77c3704ca8eaa5d5808f117d57f1e1d Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:19:13 +0330 Subject: [PATCH 07/10] Update user.py user info gql fix + implemented in public_request + avoid headers to be updated --- instagrapi/mixins/user.py | 1 - 1 file changed, 1 deletion(-) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index f782a7c7..c5a29934 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -140,7 +140,6 @@ def user_info_by_username_gql(self, username: str) -> User: User An object of User type """ - temporary_public_headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} update_headers = False data = extract_user_gql(json.loads(self.public_request(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=temporary_public_headers))['data']['user'], update_headers=update_headers) From 7c329b5dd2d80ee02d542400b168a615f6d5854b Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:20:45 +0330 Subject: [PATCH 08/10] Update user.py --- instagrapi/mixins/user.py | 1 + 1 file changed, 1 insertion(+) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index c5a29934..a87634f1 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -140,6 +140,7 @@ def user_info_by_username_gql(self, username: str) -> User: User An object of User type """ + username = str(username).lower() temporary_public_headers = {'Host': 'www.instagram.com','X-Requested-With': 'XMLHttpRequest','Sec-Ch-Prefers-Color-Scheme': 'dark','Sec-Ch-Ua-Platform': '"Linux"','X-Ig-App-Id': '936619743392459','Sec-Ch-Ua-Model': '""','Sec-Ch-Ua-Mobile': '?0','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.6261.112 Safari/537.36','Accept': '*/*','X-Asbd-Id': '129477','Sec-Fetch-Site': 'same-origin','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://www.instagram.com/','Accept-Language': 'en-US,en;q=0.9','Priority': 'u=1, i'} update_headers = False data = extract_user_gql(json.loads(self.public_request(f'https://www.instagram.com/api/v1/users/web_profile_info/?username={username}', headers=temporary_public_headers))['data']['user'], update_headers=update_headers) From faf875dae3d834d5c23a7ad6cc59e274e26382dc Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Tue, 7 May 2024 09:58:54 +0330 Subject: [PATCH 09/10] Update public.py fix missing comma --- instagrapi/mixins/public.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instagrapi/mixins/public.py b/instagrapi/mixins/public.py index 63a23a04..b4d91759 100644 --- a/instagrapi/mixins/public.py +++ b/instagrapi/mixins/public.py @@ -80,7 +80,7 @@ def public_request( data=None, params=None, headers=None, - update_headers=None + update_headers=None, return_json=False, retries_count=3, retries_timeout=2, From c424cf15a3fc85cef8af09044acef9d7eea40b93 Mon Sep 17 00:00:00 2001 From: SaeidB <41697758+SaeidB@users.noreply.github.com> Date: Tue, 7 May 2024 10:05:50 +0330 Subject: [PATCH 10/10] Update user.py import json --- instagrapi/mixins/user.py | 1 + 1 file changed, 1 insertion(+) diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index a87634f1..4f862c63 100644 --- a/instagrapi/mixins/user.py +++ b/instagrapi/mixins/user.py @@ -1,5 +1,6 @@ from copy import deepcopy from json.decoder import JSONDecodeError +import json from typing import Dict, List, Tuple from instagrapi.exceptions import (