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

Forbidden #67

Closed
6 of 10 tasks
abutizi opened this issue Apr 13, 2018 · 16 comments
Closed
6 of 10 tasks

Forbidden #67

abutizi opened this issue Apr 13, 2018 · 16 comments

Comments

@abutizi
Copy link

abutizi commented Apr 13, 2018

Before submitting an issue, make sure you have:

  • Updated to the lastest version v1.5.3
  • 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/)

Purpose of your issue?

  • Bug report (encountered problems/errors)
  • Feature request (request for a new functionality)
  • Question
  • Other

Issue reproduction: I'm using the un-authorized access:

web_api = Client(auto_patch=False, drop_incompat_keys=False)

user_info = _get_user_info('haydar.aimon')


For a bug report, you must include the Python version used, code that will reproduce the error, and the error log/traceback.

Paste the output of python -V here:

Code:

Traceback (most recent call last):
  File "C:\Users\hayda\Google Drive\Websites\Webapp\New API\instagram_private_api-master\instagram_web_api\client.py", line 234, in _make_request
    res = self.opener.open(req, data=data, timeout=self.timeout)
  File "C:\Program Files\Python36\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Program Files\Python36\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Program Files\Python36\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "C:\Program Files\Python36\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Program Files\Python36\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Error/Debug Log:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\hayda\Google Drive\Websites\Webapp\New API\instagram_private_api-master\test.py", line 19, in <module>
    user_info = web_api.user_info2('haydar.aimon')
  File "C:\Users\hayda\Google Drive\Websites\Webapp\New API\instagram_private_api-master\instagram_web_api\client.py", line 314, in user_info2
    info = self._make_request(endpoint, query={'__a': '1'})
  File "C:\Users\hayda\Google Drive\Websites\Webapp\New API\instagram_private_api-master\instagram_web_api\client.py", line 244, in _make_request
    raise ClientError('HTTPError "{0!s}" while opening {1!s}'.format(e.reason, url), e.code)
instagram_web_api.errors.ClientError: HTTPError "Forbidden" while opening https://www.instagram.com/haydar.aimon/?__a=1

Describe your issue

Thank you for this amazing web api, however I'm starting to get:
urllib.error.HTTPError: HTTP Error 403: Forbidden
on all of my requests. Did Instagram block access to this api? What can I do to resolve this issue?

@ping
Copy link
Owner

ping commented Apr 13, 2018

@Haydardi

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]

@ping ping added the no template Did not follow issue/pr template. label Apr 13, 2018
@ghost
Copy link

ghost commented Apr 13, 2018

The same issue, it seems that access to this url has been forbade by instagram.

@abutizi
Copy link
Author

abutizi commented Apr 13, 2018

@ping

Alright, have done it. Let me know if this is okay now

@abutizi
Copy link
Author

abutizi commented Apr 13, 2018

@Pavloki

Is it possible to try another url approach you think?

@2minchul
Copy link

I solved this problem. I will send a pull request soon.

@ghost
Copy link

ghost commented Apr 13, 2018

I wrote small helpful function:

def _get_user_info(username):
    # Helper function to temporary replace user_info2
    try:
        url = 'https://instagram.com/%s' % username
        resp = webapi.opener.open(url)

    except HTTPError as e:
        raise ClientError('HTTPError "{0!s}" while opening {1!s}'.format(e.reason, url), e.code)

    resp_html = resp.read().decode('utf-8')
    resp_find = re.findall('<script type="text/javascript">window._sharedData = (.*?);</script>', resp_html)
    resp_json = json.loads(resp_find[0])
    resp_info = resp_json.get('entry_data').get('ProfilePage')[0].get('graphql').get('user')

    return resp_info

It is not good solution, but it's work good. And it works slower in twice than old method.

@abutizi
Copy link
Author

abutizi commented Apr 13, 2018

@2minchul

That sounds very good, looking forward to it!

@Pavloki
Thanks so much for sharing man, appreciate it!

@ping
Copy link
Owner

ping commented Apr 13, 2018

@Haydardi Please fix your issue template. You didn't post the code used, you only posted the error trackback, so I cannot tell if you're using an authenticated or unauthenticated client.

@2minchul Thanks for your PR but I already have a similar fix in my local repo, which I'm not pushing out because there's still a bug. Can you test if your fix works when the user is authenticated? In my testing, this works only if the user is unauthenticated (no login). When the user is authenticated, it's still a 403.

@ping ping removed the no template Did not follow issue/pr template. label Apr 13, 2018
@abutizi
Copy link
Author

abutizi commented Apr 13, 2018

@ping You're right, forgot to write about that. I have updated the issue again. Short answer, I'm using the unauthenticated client.

@abutizi
Copy link
Author

abutizi commented Apr 13, 2018

@2minchul Your fix works wonders in my case (unauthenticated client)!

ping added a commit that referenced this issue Apr 13, 2018
Improve debug log for requests.
Update login.
@ping
Copy link
Owner

ping commented Apr 13, 2018

This should be fixed in cc2119b.

@ping ping closed this as completed Apr 13, 2018
@2minchul
Copy link

This issue happened again.
new md5 value is
{rhx_gis}:{variables}

@ping
Copy link
Owner

ping commented Apr 17, 2018

@2minchul Thanks for the tip. Fixed in 5133b82

@abutizi
Copy link
Author

abutizi commented Apr 17, 2018

Awesome! Thanks a lot.

Quick question. I would love to contribute to this project, especially the web API, but I’m new to this area. What libraries/frameworks should I read about in or to fully understand the web API?

@lukeify
Copy link

lukeify commented Apr 17, 2018

Are Instagram watching this project or something? There's been a number of changes in rapid succession over the past several days, and I've been using this project as a guideline on how to access the unauthenticated endpoints for my own project.

Thanks to @ping and @2minchul for all the work so far.

And hello Instagram devs! 😁👋

@abutizi
Copy link
Author

abutizi commented Apr 17, 2018

Bad news...

I'm still getting the same Forbidden error. What to do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants