Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for user info (user info gql) #1868

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions instagrapi/mixins/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
SaeidB marked this conversation as resolved.
Show resolved Hide resolved
if update_headers in [None, True] :
self.public.headers.update(headers)
elif update_headers == False :
SaeidB marked this conversation as resolved.
Show resolved Hide resolved
pass
if self.last_response_ts and (time.time() - self.last_response_ts) < 1.0:
time.sleep(1.0)
if self.request_timeout:
Expand Down
6 changes: 5 additions & 1 deletion instagrapi/mixins/user.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -141,7 +142,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"])
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'}
SaeidB marked this conversation as resolved.
Show resolved Hide resolved
update_headers = False
SaeidB marked this conversation as resolved.
Show resolved Hide resolved
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:
"""
Expand Down
Loading