作业2:通过excel读取请求入参,然后传到接口进行执行

import xlrd
from xlutils.copy import copy
import requests
import json
host='http://##authCodeLogin'
payload={"phone":"15210546986","authCode":"123456"}
s=json.dumps(payload)
header = {
'Content-Type':'application/json;charset=UTF-8'
}
r =requests.post(host,data=s,headers=header)
print(r.content)
print(r.json()['retValue']['token'])
print('登录')
host1='http://##gotoapp'
payload1={"appOpenId":"","organizationId":97966,"organizationName":"小精灵","roleId":690,"roleName":"销售经理","tenantId":50002218,"dataScope":1,"userId":1278890,"userCode":"","nickName":"韩2"}
s=json.dumps(payload1)
header1 = {
'Content-Type':'application/json;charset=UTF-8',
'Authorization':"Bearer "+str(r.json()['retValue']['token'])
}#'Bearer ' + str(a)
r1 =requests.post(host1,data=s,headers=header1)
print(r1.content)
print('获取身份')
host1='http://##/gotoapp'
payload1={"appOpenId":"","organizationId":97966,"organizationName":"小精灵","roleId":690,"roleName":"销售经理","tenantId":50002218,"dataScope":1,"userId":1278890,"userCode":"","nickName":"韩2"}
s=json.dumps(payload1)
header1 = {
'Content-Type':'application/json;charset=UTF-8',
'Authorization':"Bearer "+str(r.json()['retValue']['token'])
}#'Bearer ' + str(a)
r1 =requests.post(host1,data=s,headers=header1)
print(r1.content)
print('&&&&0814&&&&&')

old_excel = xlrd.open_workbook('L1.xlsx')
sheet = old_excel.sheets()[0]
url_3 = 'http://##/save'
headers_3 = {
'Content-Type':'application/json;charset=UTF-8',
'Authorization':"Bearer "+str(r.json()['retValue']['token'])
}
i = 0
new_excel = copy(old_excel)
for row in sheet.get_rows():
    data_3 = row[0].value
   # s_3=json.dumps(data_3)
    print(data_3)
    response_3 = requests.post(url=url_3, headers=headers_3, data=data_3)
    text = response_3.text
    print(response_3.content)
    #使用json.loads可以把Unicode类型,即json类型转换成dict类型
   # text = json.loads(text)["returnMsg"] #屏蔽这行代码即可把返回的完整数据写入文件中

    ws = new_excel.get_sheet(0)
   # ws.write(i,1,text)
   # new_excel.save('L1.xlsx')
    old_excel = xlrd.open_workbook('L1.xlsx')
    new_excel = copy(old_excel)
    i = i+1
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值