instagram_private_api: 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 x into 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:

  • Updated to the lastest version v1.6.0
  • Read the README and docs
  • Searched the bugtracker for similar issues including closed ones
  • Reviewed the sample code in tests and examples

Which client are you using?

  • app (instagram_private_api/)
  • 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/

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 7
  • Comments: 39 (1 by maintainers)

Commits related to this issue

Most upvoted comments

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()

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 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.

This issue is still present, why isn’t there any fix on the master branch yet?

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())

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

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

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')

@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.

@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

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 viewerId

in 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.

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

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" }

No solutions ? i still have the same error as @agucova

@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

This is still an issue 😃

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" }, ...

I have the same issue. In on web mode and when I tried with Client() return rhx_gis error.

Any solution? Thanks!!

Getting same error as @pyinto instagram_web_api.errors.ClientBadRequestError: HTTPError "Bad Request" while opening https://www.instagram.com/accounts/login/ajax