Created
April 8, 2016 12:35
-
-
Save absent1706/542c0b09ca574c0f6f873f345bdbaa90 to your computer and use it in GitHub Desktop.
python: debug urllib HTTPS request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import json, urllib2 | |
#адрес для отправки json-запросов | |
url = 'https://api.direct.yandex.ru/v4/json/' | |
#данные для OAuth-авторизации | |
token = '6bfc962472504a2b99fb6a5b0b181d98' | |
#логин в Директе | |
login = 'igorxlib' | |
#структура входных данных (словарь) | |
data = { | |
'method': 'GetClientInfo', | |
'token': token, | |
'locale': 'ru', | |
'param': [login] | |
} | |
#конвертировать словарь в JSON-формат и перекодировать в UTF-8 | |
jdata = json.dumps(data, ensure_ascii=False).encode('utf8') | |
h=urllib2.HTTPSHandler(debuglevel=1) | |
opener = urllib2.build_opener(h) | |
urllib2.install_opener(opener) | |
#выполнить запрос | |
response = urllib2.urlopen(url,jdata) | |
#вывести результат | |
print '' | |
print response.read().decode('utf8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment