Last active
December 27, 2015 06:08
-
-
Save chapter09/7278997 to your computer and use it in GitHub Desktop.
AmyPI Client for GET
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 httplib, urllib, json | |
import locale, datetime | |
import base64, hmac | |
from hashlib import sha1 | |
gid = 'sh600580' | |
apihub_key = 'YSBYsT2nNVBNykK1' | |
apihub_secret = 'yTL5SUQDo1rbnjz7SSVNa4ypHLjgzfLi' | |
apihub_user_id = 1 | |
url_full_path = '/api/15/v2.1/query?gid=%s'%gid | |
action = 'GET' | |
string_to_sign = action.upper() + "\n" + \ | |
"" + "\n" + \ | |
"" + "\n" + \ | |
"" + "\n" + \ | |
"%d"%apihub_user_id + "\n" + \ | |
apihub_key + "\n" + \ | |
url_full_path; # 从域名后的 / 开始到URL最后结束中间的路径 | |
# 参数包括在其中 | |
hashed_string = hmac.new(apihub_secret, string_to_sign, sha1) | |
apihub_signature = base64.b64encode(hashed_string.digest()).rstrip() | |
url = 'apiproxy.ramytech.com' | |
headers = { | |
"apihub-key": apihub_key, | |
"apihub-user-id": apihub_user_id, | |
"apihub-signature": apihub_signature, | |
} | |
conn = httplib.HTTPConnection(url, 80) | |
conn.request('GET', '/api/15/v2.1/query?gid=%s'%gid, '', headers) | |
response = conn.getresponse() | |
ret = response.read() | |
ret = json.loads(ret) | |
print ret['result'][0]['data']['name'] | |
print ret['result'][0]['data'] | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment