diff --git a/instagrapi/mixins/public.py b/instagrapi/mixins/public.py index 24a6ba55..33baa895 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,18 +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: diff --git a/instagrapi/mixins/user.py b/instagrapi/mixins/user.py index 65e01ce6..098ebe9a 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 ( @@ -149,7 +150,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_user_info_by_username(f"/{username!s}/")["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: """