# -*- coding: utf-8 -*- import urllib2 import urllib import time import md5 secret=‘xxxxx‘ app_key=‘yyyy‘ session =‘zzzzzz‘ arg={ ‘format‘: ‘json‘, ‘timestamp‘: time.strftime(‘%Y-%m-%d %H:%M:%S‘), ‘app_key‘: app_key, ‘v‘ : ‘2.0‘, ‘sign_method‘: ‘md5‘, ‘session‘ :session, ‘method‘: ‘taobao.trades.sold.get‘, ‘fields‘: ‘seller_nick,buyer_nick‘, # taobao.trades.sold.get 方法用到的应用参数, ‘type‘:‘tmall_i18n‘, # taobao.trades.sold.get 方法用到的应用参数, } keys = arg.keys() keys.sort() str=‘‘ #参数排序后连接字串 ‘k‘+‘v‘ for k in keys: str+=k +arg[k] #首尾加上 secret str= secret + str + secret #md5编码后转大写 sign=md5.md5(str).hexdigest().upper() postDict = arg.copy() #rul 请求加上 签名 postDict.update( {‘sign‘: sign} ) postData = urllib.urlencode(postDict); req = urllib2.Request(‘http://gw.api.taobao.com/router/rest‘, postData); resp = urllib2.urlopen(req) print resp.read()