Instagram Python Requests Log In Without Api
Solution 1:
RFC 7231 states the following:
403 Forbidden
The 403 (Forbidden) status code indicates that the server understood the request but refuses to authorize it. A server that wishes to make public why the request has been forbidden can describe that reason in the response payload (if any).
If authentication credentials were provided in the request, the server considers them insufficient to grant access. The client SHOULD NOT automatically repeat the request with the same credentials. The client MAY repeat the request with new or different credentials. However, a request might be forbidden for reasons unrelated to the credentials.
So it looks like server will not allow you to access desired data without using official API.
Solution 2:
I played around with your code, and as is, it does indeed return a 403.
However, it can be fixed by adding a csrfmiddlewaretoken property to the data variable sent in your POST request. Change the line in your code from:
login_data = {"username": "<user>", "password": "<pass>"}
to
login_data = {"csrfmiddlewaretoken": req.cookies['csrftoken'], "username": "<user>", "password": "<pass>"}
Also, add a /ajax
to the end of your login_url
variable. Otherwise it won't authenticate.
It'll give you a 200 code after that. Good luck!
Post a Comment for "Instagram Python Requests Log In Without Api"