From bb5c869e938844028e3c66351edc55ec668452ca Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Thu, 6 Apr 2017 23:04:42 +0800 Subject: [PATCH] Fix exchange_code_for_access_token by supplying Content-Type info Otherwise, it will fail with the following error Traceback (most recent call last): File "get_access_token.py", line 49, in access_token = api.exchange_code_for_access_token(code) File "/home/yousong/git-repo/python-instagram/instagram/oauth2.py", line 48, in exchange_code_for_access_token return req.exchange_for_access_token(code=code) File "/home/yousong/git-repo/python-instagram/instagram/oauth2.py", line 116, in exchange_for_access_token raise OAuth2AuthExchangeError(parsed_content.get("error_message", "")) instagram.oauth2.OAuth2AuthExchangeError: You must provide a client_id --- instagram/oauth2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instagram/oauth2.py b/instagram/oauth2.py index 053b1be8..1011389e 100644 --- a/instagram/oauth2.py +++ b/instagram/oauth2.py @@ -109,7 +109,8 @@ def exchange_for_access_token(self, code=None, username=None, password=None, sco data = self._data_for_exchange(code, username, password, scope=scope, user_id=user_id) http_object = Http(disable_ssl_certificate_validation=True) url = self.api.access_token_url - response, content = http_object.request(url, method="POST", body=data) + headers = {'Content-Type': 'application/x-www-form-urlencoded'} + response, content = http_object.request(url, method="POST", headers=headers, body=data) parsed_content = simplejson.loads(content.decode()) if int(response['status']) != 200: raise OAuth2AuthExchangeError(parsed_content.get("error_message", ""))