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

[BUG] JSONDecodeError in _send_private_request when invalid api request #708

Open
hittiks opened this issue Jun 10, 2022 · 0 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@hittiks
Copy link

hittiks commented Jun 10, 2022

In instagrapi > mixins > private.py > PrivateRequestMixin > _send_private_request have this code (line 315 for me):

except requests.HTTPError as e:
    try:
        self.last_json = last_json = response.json()
    except JSONDecodeError:
        pass
    message = last_json.get("message", "")

in this scope JSONDecodeError = json.decoder.JSONDecodeError
but when trying to make a deliberately invalid api request (e.g. https://i.instagram.com/api/v1/track/698069981278947/info/)
except JSONDecodeError don't work because raised requests.exceptions.JSONDecodeError and you get big html in terminal

possible way to solve the problem: replace json.decoder.JSONDecodeError to requests.exceptions.JSONDecodeError and you will only get something like this (this 2 lines NOT printed in terminal when used json.decoder.JSONDecodeError):

Status 404: Endpoint /v1/audio/698069981278947/info/ does not exists
404 Client Error: Not Found for url: https://i.instagram.com/api/v1/audio/698069981278947/info/

without one more exceptions and long html

did I solve the problem or long html and exceptions should have been there?

@hittiks hittiks added the bug Something isn't working label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants