instagram_private_api
instagram_private_api copied to clipboard
WebAPI: Unable to get rhx_gis from init request
Please follow the guide below
- Issues submitted without this template format will be ignored.
- Please read the questions carefully and answer completely.
- Do not post screenshots of error messages or code.
- Put an
xinto all the boxes [ ] relevant to your issue (==> [x] no spaces). - Use the Preview tab to see how your issue will actually look like.
- Issues about reverse engineering is out of scope and will be closed without response.
- Any mention of spam-like actions or spam-related tools/libs/etc is strictly not allowed.
Before submitting an issue, make sure you have:
- [x] Updated to the lastest version v1.6.0
- [x] Read the README and docs
- [x] Searched the bugtracker for similar issues including closed ones
- [x] Reviewed the sample code in tests and examples
Which client are you using?
- [ ] app (
instagram_private_api/) - [x] web (
instagram_web_api/)
Describe your issue
Hi everyone,
From today web api will report error "Unable to get rhx_gis from init request". I researched about this issue in other projects, some suggest to remove rhx_gis and X-Instagram-GIS, I tried this solution, at first it could successfully login and call api, but later web api reported "instagram_web_api.errors.ClientBadRequestError". I had also processed the challenges from IG website, but still no success any more.
Would be very nice if someone finds how to fix this new change.
Thanks.
Paste the output of python -V here:
Code:
# Example code that will produce the error reported
from instagram_web_api import Client
api = Client(proxy=getProxy(), settings=None,
username=username, password=password)
api.login()
Error/Debug Log:
File "/Library/Python/2.7/site-packages/instagram_web_api/client.py", line 390, in login
login_res = self._make_request('https://www.instagram.com/accounts/login/ajax/', params=params)
File "/Library/Python/2.7/site-packages/instagram_web_api/client.py", line 291, in _make_request
raise ClientBadRequestError(msg, e.code)
ClientBadRequestError: HTTPError "Bad Request" while opening https://www.instagram.com/accounts/login/ajax/
@xinhuang327
Your issue report does not conform to the issue template that has been specified for this repo: https://raw.githubusercontent.com/ping/instagram_private_api/master/.github/ISSUE_TEMPLATE.md
Please edit your issue to comply with the template requirement.
This issue will be closed after 24 hours if no followup action is taken.
[This comment is auto-generated. ref=notemplate]
I'm getting the same issue. Using version 1.6.0, with instagram_web_api.
When I call:
Client(auto_patch=True, drop_incompat_keys=False)
I get
ClientError: Unable to get rhx_gis from init request.
Yes, the same issue. rhx_gis was expelled from IG response
I've just run into the same issue and fixed it temporarily by using a static rhx_gis that I found online. Use something like this to get it working for now:
rhx_gis = self._extract_rhx_gis(init_res_content) or "4f8732eb9ba7d1c8e8897a75d6474d4eb3f5279137431b2aafb71fafe2abe178"
Edit: I've just tried using any string as a rhx_gis and everything still works neatly.
I do not work with this library, but I also encountered this problem. With the help of js reverse, I seem to have found a solution.
In sharedData data is output on the page. See field config->viewerId. It is now transmitted instead of rhx_gis. The string to form md5 looks like: :{"id":"11612471724"}, where the numbers are viewerId
in this way,
rhx_gis = md5(':{"id":"viewerId"}')
sharedData fragment:
{ "config": { "csrf_token": "xoKnKvuk9HXYAyO7nwNP9BQVxfxvlEvw", "viewerId": "11612471724" }, ...
Based on two upper commenters:
line 317 in client.py
def _extract_rhx_gis(html):
tmp_str = ':{"id":"'+f'{random.randint(10000000,99999999)}'+'"}'
return hashlib.md5(b'tmp_str')
Will solve the problem
Based on two upper commenters:
line 317 in client.py
def _extract_rhx_gis(html): tmp_str = ':{"id":"'+f'{random.randint(10000000,99999999)}'+'"}' return hashlib.md5(b'tmp_str')Will solve the problem
I do not work with this library, but I also encountered this problem. With the help of js reverse, I seem to have found a solution.
In sharedData data is output on the page. See field config->viewerId. It is now transmitted instead of rhx_gis. The string to form md5 looks like:
:{"id":"11612471724"}, where the numbers are viewerIdin this way,
rhx_gis = md5(':{"id":"viewerId"}')sharedData fragment:
{ "config": { "csrf_token": "xoKnKvuk9HXYAyO7nwNP9BQVxfxvlEvw", "viewerId": "11612471724" }, ...
You can actually put any string there and it will work, you don't have to extract anything. I've tried that myself though.
Based on two upper commenters:
line 317 in client.py
def _extract_rhx_gis(html): tmp_str = ':{"id":"'+f'{random.randint(10000000,99999999)}'+'"}' return hashlib.md5(b'tmp_str')Will solve the problem
This works for Python 3 Here is a solution which works on 2.7 for me
def _extract_rhx_gis(html):
tmp_str = ':{"id":{"'+ "{}" +'"}}'.format(random.randint(10000000,99999999))
return hashlib.md5(b'tmp_str')
Had to make some changes to the code above to make it work:
def _extract_rhx_gis(html):
tmp_str = ':{"id":"'+f'{random.randint(10000000,99999999)}'+'"}'
return hashlib.md5(tmp_str.encode()).hexdigest()
b'tmp_str' is just the string 'tmp_str', which negates the point of generating one
This is still an issue :)
I've put the fix that @Mithorium suggested in a fork and made a pull request into the base repository. Take it or leave it but I hope this can be resolved soon!
Instagram's changed their APIs out from under us before and it's always a bit of a fire drill getting them up and running again
I'm still having this problem. I don't think the PR will be accepted though @thekensman , both lines of code added produce security issues in Codacy.
Yes I'm not sure if there's a more secure fix to be had - the PR is there for convenience, or to inspire a more robust solution to replace it
I've fixed this issue with creating new class and overwrite it's static method.
import hashlib
import string
import random
from instagram_web_api import Client
class MyClient(Client):
@staticmethod
def _extract_rhx_gis(html):
options = string.ascii_lowercase + string.digits
text = ''.join([random.choice(options) for _ in range(8)])
return hashlib.md5(text.encode())
for some reasons @pourya2374 's code gives me an error. So I edited it slightly to fix this error:
import hashlib
import string
import random
from instagram_web_api import Client
class MyClient(Client):
@staticmethod
def _extract_rhx_gis(html):
options = string.ascii_lowercase + string.digits
text = ''.join([random.choice(options) for _ in range(8)])
return hashlib.md5(text.encode()).hexdigest()
This issue is still present, why isn't there any fix on the master branch yet?
@javad94 it worked for me a few weeks but suddenly I'm getting the same error:
instagram_web_api.errors.ClientBadRequestError: HTTPError "Bad Request" while opening https://www.instagram.com/accounts/login/ajax/
77db6e1c30c697195362aa4ed593
Getting same error as @pyinto
instagram_web_api.errors.ClientBadRequestError: HTTPError "Bad Request" while opening https://www.instagram.com/accounts/login/ajax
@pyinto @reformedot Instagram does not allow sending a plain text password at accounts/login/ajax/ anymore, it requires enc_password parameter instead. Refer to this dilame/instagram-private-api#1010
I provided a fix with code from @javad94
@eracle I tried your fix, but as others described, now I'm getting:
instagram_web_api.errors.ClientBadRequestError: HTTPError "Bad Request" while opening https://www.instagram.com/accounts/login/ajax/
Not sure how to fix per the enc_password parameter, as @fenchelfen pointed out.
No solutions ? i still have the same error as @agucova
Here is the working solution as of 1 July, use MyClient instead of using the libraries class directly.
import hashlib
import string
import random
from instagram_web_api import Client, ClientCompatPatch, ClientError, ClientLoginError
import datetime
class MyClient(Client):
@staticmethod
def _extract_rhx_gis(html):
options = string.ascii_lowercase + string.digits
text = ''.join([random.choice(options) for _ in range(8)])
return hashlib.md5(text.encode()).hexdigest()
def login(self):
"""Login to the web site."""
if not self.username or not self.password:
raise ClientError('username/password is blank')
time = str(int(datetime.datetime.now().timestamp()))
enc_password = f"#PWD_INSTAGRAM_BROWSER:0:{time}:{self.password}"
params = {'username': self.username, 'enc_password': enc_password, 'queryParams': '{}', 'optIntoOneTap': False}
self._init_rollout_hash()
login_res = self._make_request('https://www.instagram.com/accounts/login/ajax/', params=params)
if not login_res.get('status', '') == 'ok' or not login_res.get ('authenticated'):
raise ClientLoginError('Unable to login')
if self.on_login:
on_login_callback = self.on_login
on_login_callback(self)
return login_res
No solutions ? i still have the same error as @agucova
Please take a look at the code above.
No solutions ? i still have the same error as @agucova
Please take a look at the code above.
I'm sorry, but I'm being stupid. I don't know how to add cookies to them, I get an error.
Unexpected exception: _ _ init__ () accepts 1 to 2 positional arguments bat 3 were given
In the line:
api = MyClient(
username, password,
on_login=lambda x: self.onlogin_callback(x, self.file_name))
I'm just trying to create and make an example from here: https://github.com/ping/instagram_private_api/blob/master/examples/savesettings_logincallback.py
No solutions ? i still have the same error as @agucova
Please take a look at the code above.
I'm sorry, but I'm being stupid. I don't know how to add cookies to them, I get an error.
Unexpected exception: _ _ init__ () accepts 1 to 2 positional arguments bat 3 were givenIn the line:
api = MyClient( username, password, on_login=lambda x: self.onlogin_callback(x, self.file_name))I'm just trying to create and make an example from here: https://github.com/ping/instagram_private_api/blob/master/examples/savesettings_logincallback.py
well actually you have to remove the self before 'onlogin_callback'
Hey guys, this is web enc_password api:
https://leesoar.com/api-v1/ig?pub_key=20ed90203c457a2f9efc20820c2452403bff6424de39ff9cc928a751e07f6915&pub_id=229&pwd=xxx&t=1596703337&secret_key=a9ad0489a73146c68ec514ffce5cbaba
the secret_key have 200 times.
- "t" is timestamp
- "pwd" is password
- "version" is pub_version, and default is 10
- "action" default is "enc_password"
It returns:
{ "code": 1, "message": "ok", "enc_password": "#PWD_INSTAGRAM_BROWSER:10:1596703337:AQpQAH4W1vHVVa7730diM49fhY5Cn0CsgfGsZ5zA613WkRJDn3ujkqqwEdtnV7BrjgJsW3zinQ1OrSnTdgU2We72gWztHxM7OW2NSfvVR/4AGuCZGbR8mpk30wEzP4Z9tPLfxmr/o3Nmk6v7", "pub_key": "20ed90203c457a2f9efc20820c2452403bff6424de39ff9cc928a751e07f6915", "pub_id": "229", "pwd": "xxx", "version": 10, "t": "1596703337" }
python 2.7 script version of @HashamGhuffary
import hashlib
import string
import random
from instagram_web_api import Client, ClientCompatPatch, ClientError, ClientLoginError
import time
class MyClient(Client):
@staticmethod
def _extract_rhx_gis(html):
options = string.ascii_lowercase + string.digits
text = ''.join([random.choice(options) for _ in range(8)])
return hashlib.md5(text.encode()).hexdigest()
def login(self):
self.username = ''
self.password = ''
"""Login to the web site."""
if not self.username or not self.password:
raise ClientError('username/password is blank')
#time = str(int(datetime.datetime.now().timestamp()))
#enc_password = f"#PWD_INSTAGRAM_BROWSER:0:{time}:{self.password}"
enc_password = ("#PWD_INSTAGRAM_BROWSER:0:{}:{}".format(int(time.time()), self.password)) #python2.7
params = {'username': self.username, 'enc_password': enc_password, 'queryParams': '{}', 'optIntoOneTap': False}
self._init_rollout_hash()
login_res = self._make_request('https://www.instagram.com/accounts/login/ajax/', params=params)
if not login_res.get('status', '') == 'ok' or not login_res.get ('authenticated'):
raise ClientLoginError('Unable to login')
if self.on_login:
on_login_callback = self.on_login
on_login_callback(self)
return login_res
I have the same issue. In on web mode and when I tried with Client() return rhx_gis error.
Any solution? Thanks!!
Here is the working solution as of 1 July, use MyClient instead of using the libraries class directly.
import hashlib import string import random from instagram_web_api import Client, ClientCompatPatch, ClientError, ClientLoginError import datetime class MyClient(Client): @staticmethod def _extract_rhx_gis(html): options = string.ascii_lowercase + string.digits text = ''.join([random.choice(options) for _ in range(8)]) return hashlib.md5(text.encode()).hexdigest() def login(self): """Login to the web site.""" if not self.username or not self.password: raise ClientError('username/password is blank') time = str(int(datetime.datetime.now().timestamp())) enc_password = f"#PWD_INSTAGRAM_BROWSER:0:{time}:{self.password}" params = {'username': self.username, 'enc_password': enc_password, 'queryParams': '{}', 'optIntoOneTap': False} self._init_rollout_hash() login_res = self._make_request('https://www.instagram.com/accounts/login/ajax/', params=params) if not login_res.get('status', '') == 'ok' or not login_res.get ('authenticated'): raise ClientLoginError('Unable to login') if self.on_login: on_login_callback = self.on_login on_login_callback(self) return login_res
I'm a little confused? Where does this go? Does anything else need to be replaced so that the MyClient class will be used instead?
@ajbenz18 you should put that at top of your script.