- import httplib
- import urllib
- import json
- import hashlib
- import hmac
- # Replace these with your own API key data
- api_key = "5a8808b25e3f59d8818d3fbc0ce993fbb82dcf90"
- api_secret = "5a8808b25e3f59d8818d3fbc0ce993fbb82dcf90"
- # Come up with your own method for choosing an incrementing nonce
- nonce = 13
- # method name and nonce go into the POST parameters
- params = {"nonce": nonce}
- params = urllib.urlencode(params)
- # Hash the params string to produce the Sign header value
- H = hmac.new(api_secret, digestmod=hashlib.sha512)
- H.update(params)
- sign = H.hexdigest()
- headers = {"Content-type": "application/x-www-form-urlencoded",
- "Key":api_key,
- "Sign":sign}
- conn = httplib.HTTPSConnection("www.cryptsy.com/api",443)
- conn.request("POST", "pubapi.cryptsy.com/api.php?method=orderdata", params, headers)
- #response = conn.getresponse()
- #print response.status, response.reason
- #print json.load(response)
- conn.close()
- 提示错误:
- Traceback (most recent call last):
- File "C:/Python27/mmmmm.py", line 26, in <module>
- conn.request("POST", "pubapi.cryptsy.com/api.php?method=orderdata", params, headers)
- File "C:\\Python27\\lib\\httplib.py", line 946, in request
- self._send_request(method, url, body, headers)
- File "C:\\Python27\\lib\\httplib.py", line 987, in _send_request
- self.endheaders(body)
- File "C:\\Python27\\lib\\httplib.py", line 940, in endheaders
- self._send_output(message_body)
- File "C:\\Python27\\lib\\httplib.py", line 803, in _send_output
- self.send(msg)
- File "C:\\Python27\\lib\\httplib.py", line 755, in send
- self.connect()
- File "C:\\Python27\\lib\\httplib.py", line 1152, in connect
- self.timeout, self.source_address)
- File "C:\\Python27\\lib\\socket.py", line 551, in create_connection
- for res in getaddrinfo(host, port, 0, SOCK_STREAM):
- gaierror: [Errno 11001] getaddrinfo failed
- 不知道为什么
- #该片段来自于http://www.codesnippet.cn/detail/130220148696.html
来源: http://www.codesnippet.cn/detail/130220148696.html