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
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion instagrapi/mixins/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you set up new headers here? Please use the existing methods. Otherwise, the user cannot set its own headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new endpoint for user info need some new headers and user-agent and the old headers wont work , this is the reason i put headers directly , and instagrapi users wont need to change headers in gql requests like this request , so the better idea is to use headers directly in endpoints like this , understood ?

Copy link
Contributor

@claell claell Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh. But just giving new headers hard coded is not a clean way to go in that case, either. This might also result in Instagram banning clients, if they see requests with different user agents from the same IP.

So, how do the new headers differ from the old expected ones? Can they somehow get translated into each other? Or be set explicitly somewhere, like the old headers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as i said this is a public request (gql , or non auth request) , and the headers are same everytime you send request , even the current model uses same headers everytime (for public request) ( monitor the instagrapi requests so you can see ) , so instagram will not ban you ,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if I set a different user agent, this won't get used for this request. Also, and I repeat, hardcoding the header here is the wrong place.

I am happy to assist you with improving the code quality. But I hope, you can understand why this is not good coding style.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the instagrapi gql requests , the headers are same everytime , it uses its own user agent , not logged-in client user agent (mobile), not base_headers , if you use another user agent for this request , it will return you "mismatch user agent error etc"

SaeidB marked this conversation as resolved.
Show resolved Hide resolved
#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'])
SaeidB marked this conversation as resolved.
Show resolved Hide resolved
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']
SaeidB marked this conversation as resolved.
Show resolved Hide resolved

SaeidB marked this conversation as resolved.
Show resolved Hide resolved

def user_info_by_username_v1(self, username: str) -> User:
"""
Expand Down
Loading