首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用requests.post (Python)发送数组?“值错误:要解压缩的值太多”

如何使用requests.post (Python)发送数组?“值错误:要解压缩的值太多”
EN

Stack Overflow用户
提问于 2015-07-02 02:21:00
回答 2查看 86.6K关注 0票数 77

我尝试使用requests.post向WheniWork接口发送一个请求数组(列表),但一直收到两个错误中的一个。当我将列表作为列表发送时,我得到一个解包错误,当我将它作为字符串发送时,我得到一个错误,要求我提交一个数组。我认为这与请求处理列表的方式有关。下面是一些示例:

代码语言:javascript
复制
url='https://api.wheniwork.com/2/batch'
headers={"W-Token": "Ilovemyboss"}
data=[{'url': '/rest/shifts', 'params': {'user_id': 0,'other_stuff':'value'}, 'method':'post',{'url': '/rest/shifts', 'params': {'user_id': 1,'other_stuff':'value'}, 'method':'post'}]
r = requests.post(url, headers=headers,data=data)
print r.text

# ValueError: too many values to unpack

简单地将数据的值括在引号中:

代码语言:javascript
复制
url='https://api.wheniwork.com/2/batch'
headers={"W-Token": "Ilovemyboss"}
data="[]" #removed the data here to emphasize that the only change is the quotes
r = requests.post(url, headers=headers,data=data)
print r.text

#{"error":"Please include an array of requests to make.","code":5000}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31168819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档