python做接口测试报错TypeError: request() got an unexpected keyword argument 'header'


代码如下:

# 模块
import requests

# 接口请求地址
URL = "https://testapi.5eck.cn/goods/*********ByStatus"

# 请求头设置
head = {"Authorization": "Bearer 4f6*************5-9fbe-58d1c7cf5a2b"}

# 发送无参数请求
r = requests.get(url=URL, header=head)

# 获取返回的json数据
result = r.json()

# 打印返回的数据
print(result)

报错:TypeError: request() got an unexpected keyword argument 'header'

翻译,request()得到一个意外的关键字参数“header”  意思是,request模块没有关键字参数header,检查后发现,是headers

关键字参数名称是headers,后面有s的

正确如下

# 发送无参数请求
r = requests.get(url=URL, headers=head)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM