M
M
mikemoix2015-03-25 17:43:53
Python
mikemoix, 2015-03-25 17:43:53

Authorization in instagram?

There is a need to write a script to get an access token in instagram. Did according to this article habrahabr.ru/post/143972 . Accordingly, I changed it to what is needed for instagram

url_string = "https://instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=code" % (self.__cient_id_, self.__redirect_uri_)

parser.params["username"] = login
parser.params["password"] = password

if parser.method == "POST":
                response = opener.open((parser.url), urllib.urlencode(parser.params))

on the last line it crashes with the error urllib2.HTTPError: HTTP Error 403: FORBIDDEN
I don’t know what to think anymore
here is the authorization form
form method="POST" id="login-form" class="adjacent" action="/accounts/login/?force_classic_login=&next=/oauth/authorize/%3Fclient_id%3D07456f3a5026417b97e166e0558995f4%26redirect_uri%3Dhttps%3A//limitless-wave-5692.herokuapp.com%26response_type%3Dcode">
<input type="hidden" name="csrfmiddlewaretoken" value="71ca4f35b134dcc299c1c2092a97bb2d"/>
<p><label for="id_username">Имя пользователя:</label> <input name="username" maxlength="30" autocapitalize="off" autocorrect="off" type="text" id="id_username" /></p>
<p><label for="id_password">Пароль:</label> <input autocapitalize="off" autocorrect="off" type="password" name="password" id="id_password" /></p>
<p class="form-actions">
<a href="/accounts/password/reset/">Забыли пароль?</a>
<input type="submit" class="button-green" value="Войти" />
</p>
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2015-03-25
@un1t

I suspect that 403 is due to the fact that csrfmiddlewaretoken is not passed from the form.
Those. make a GET request to the form, parse the token from the form, and make a POST request with our parameters.
I recommend the requests library.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question