Skip to content

Getting JSON response from Instagram stories API Python #21431

Answered by mpboom
CodeWithAwais asked this question in General
Getting JSON response from Instagram stories API Python #21431
Sep 27, 2021 · 1 answer

I got this API request when open a story on Instagram Login • Instagram
But, the issue is that when you open the same link even in the browser, it gives this response back
{"message":"useragent mismatch","status":"fail"}
How can we get the correct response back which is shown in the network tab? Or is it possible to get the content directly from the chrome dev tool network tab?

I have attached the screenshot of from network tab below
image

Hey @CodeWithAwais and welcome!

In general, it’s often not the most reliable to copy DevTools requests. Rather, try making use of the official Instagram API.

If you’re determined to follow this path, make sure everything in your Python session is the same as in your browser session. Think about not only URLs and their parameters, but also cookies and, what seems to break you up in this case, headers like the User-Agent header.

If you’re using the Python requests module, you can use a request.Session() and pass in those headers and cookies from the start.

Replies

1 suggested answer

Hey @CodeWithAwais and welcome!

In general, it’s often not the most reliable to copy DevTools requests. Rather, try making use of the official Instagram API.

If you’re determined to follow this path, make sure everything in your Python session is the same as in your browser session. Think about not only URLs and their parameters, but also cookies and, what seems to break you up in this case, headers like the User-Agent header.

If you’re using the Python requests module, you can use a request.Session() and pass in those headers and cookies from the start.

0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
General
Labels
None yet
2 participants