影刀上传文件api
import requests
yingdao_Info={
"accessKeyId":"XXX",
"accessKeySecret":"XXX",
"accountName": 'xm@bjywz',
"robotUuid":"XXX",
"file_path":"D:\\desktop\\影刀数据表格_20240822-101819.xlsx",
#文件的新名字,自定义
"flie_name":"123.xlsx"
}
#1.获取token
def get_access_token():
url="https://api.yingdao.com/oapi/token/v2/token/create"
headers={
"Content-Type":"application/x-www-form-urlencoded"
}
params={
"accessKeyId":yingdao_Info["accessKeyId"],
"accessKeySecret":yingdao_Info["accessKeySecret"]
}
response = requests.post(url=url,headers=headers,params=params)
return response.json()['data']['accessToken']
# print(get_access_token())
#2、上传文件
def Upload_files():
url="https://api.winrobot360.com/oapi/dispatch/v2/file/upload"
headers={
"Authorization":f"Bearer {access_token}"
}
files={'file':(yingdao_Info["flie_name"],open(yingdao_Info["file_path"],'rb'),"multipart/form-data")}
response = requests.post(url=url,headers=headers,files=files)
# print(f"影刀返回:\n{response.json()}")
return response.json()
#3、启动应用
def start_application():
url="https://api.yingdao.com/oapi/dispatch/v2/job/start"
headers={
"Authorization":f"Bearer {access_token}",
"Content-Type":"application/json"
}
body={
"accountName": yingdao_Info["accountName"],
"robotUuid":yingdao_Info["robotUuid"],
"params":[
{
"name":"上传的Excel文件",
"value":fileKey,
"type":"file"
},
]
}
response = requests.post(url=url,headers=headers,json=body)
print(f"影刀启动应用返回:\n{response.json()}")
return response.json()['data']
access_token=get_access_token()
fileKey=Upload_files()['data']['fileKey']
start_application()