def getAladdinRequest(data_type, request_data = [], logfile = False):
result = {'msg':'OK', 'data':''}
curr = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
conf = getAladdinConf()
clt = AcsClient(conf['AppKey'],conf['AppSecret'],conf['region_id'])
if data_type in conf:
#url = conf['baseURL'] + conf[data_type]['url']
url = 'http://0bbbae2b380a49238d3b7317d2cd7e86-cn-hangzhou.alicloudapi.com/index.php/rest/V2/product/price' #test url
headers = conf['reqheader']
#host = conf['hzHost']
print('---> Access to ' + url)
# print('---> Headers: ' + json.dumps(headers))
if conf[data_type]['method'] == 'POST':
payload = json.dumps({"sku":request_data})
req_post = requests.post(url = url, headers = headers,data=https://bbs.csdn.net/topics/payload)
r = clt.do_action_with_exception(req_post) #感覺是這里有問題,大師能否幫忙看看。
line = r.text
else:
r = requests.get(url, headers = headers)
line = r.text
if logfile:
logfile.write('>>- ' + curr + '\n')
logfile.write(' >>> ' + str(request_data) + '\n')
logfile.write('... ' + line + '\n')
else:
logfile.write('>>- ' + curr + '\n')
logfile.write('>>>Error, unknown data type: ' + data_type + '\n')
LEN_TH = 41943040 # 40M
if len(line) > LEN_TH:
result['msg'] = 'SIZE_TOO_BIG'
else:
result['data'] = line
return result
error information:
r = clt.do_action_with_exception(req_post)
File "D:\apps\py36\lib\site-packages\aliyunsdkcore\client.py", line 472, in do_action_with_exception
acs_request.set_accept_format('JSON')
AttributeError: 'Response' object has no attribute 'set_accept_format'
uj5u.com熱心網友回復:
通過js代碼能調通。如下:const Client = require('aliyun-api-gateway').Client;
let client = new Client(APP_KEY, APP_SECRET);
let result = await client.post(url, {
headers,
data,
})
async function _getHeaders(secretToken) {
let headers = {
"Authorization": `Bearer ${secretToken}`,
"Content-Type": "application/json",
"Auth-Code": "hz",
"User-Agent": 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
}
return headers;
}
python應該怎么寫呢?請大俠幫忙。
uj5u.com熱心網友回復:
首先,do_action_with_exception()括號里面應該是request而不是response。轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/13307.html
上一篇:自關聯(初了解)
