Home > other >  Python needs through ali cloud gateway authentication, has been adjusted
Python needs through ali cloud gateway authentication, has been adjusted

Time:11-20

Def getAladdinRequest (data_type, request_data=https://bbs.csdn.net/topics/[], logfile=False) :
Result={' MSG ':' OK 'and' data ':'}
Curr=datetime. Datetime. Now (). The strftime (' % % Y - m - H: % d % % m: % S ')
The conf=getAladdinConf ()
Cli=AcsClient (conf [' AppKey], the conf [' AppSecret], the 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 (" -- -- -- & gt; Access to the '+ url)
# print (' - & gt; Headers: "+ json. Dumps (Headers))
If the conf [data_type] [' method ']=='POST' :
Content=json. Dumps ({" sku ": request_data})
Req_post=requests. Post (url=url, headers=headers, data=https://bbs.csdn.net/topics/payload)

R=cli. Do_action_with_exception (req_post) # feeling is here have a question, the master can help see,
The line=r.t ext
The else:
R=requests. Get (url, headers=headers)
The line=r.t ext
If logfile:
Logfile. Write (' & gt;> - '+ curr +' \ n ')
Logfile. Write (' & gt;> '+ STR (request_data) +' \ n ')
Logfile. Write ('... '+ line +' \ n ')
The else:
Logfile. Write (' & gt;> - '+ curr +' \ n ')
Logfile. Write (' & gt;> Unknown Error, data type: '+ data_type +' \ n ')
LEN_TH=41943040 # 40 m
If len (line) & gt; LEN_TH:
Result [' MSG ']='SIZE_TOO_BIG'
The else:
Result [' data ']=line
Return the result

The error information:
R=cli. Do_action_with_exception (req_post)
The File "D: \ apps \ py36 \ lib \ site - packages \ aliyunsdkcore \ client py", line 472, in do_action_with_exception
Acs_request. Set_accept_format (' JSON)
AttributeError: 'the Response object has no attribute' set_accept_format '

CodePudding user response:

By js code to transfer, as follows:
Const Client=the require (' aliyun - API - gateway). The Client;
Let the client=new client (APP_KEY, APP_SECRET);
Let the result=await client. Post (url, {
Headers,
Data,
})

Async function _getHeaders (secretToken) {
Let headers={
"Authorization" : ` Bearer ${secretToken} `,
"The content-type" : "application/json,"
"Auth - Code" : "hz",
"The user-agent:" 'the Mozilla/5.0 (compatible; Googlebot/2.1; + '
http://www.google.com/bot.html)}
Return headers.
}

Python should be how to write? Please help warrior,

CodePudding user response:

First of all, do_action_with_exception () brackets should be request rather than inside the response,
  • Related