python - 在 Python 请求数据中包含列表

标签 python http python-2.7 python-requests url-encoding

我正在使用 Requests 库将数据 PUTPipeline Deals API ,并且数据要求我在请求data中放置一个值的列表。

他们的示例:"custom_label_83": [ 28, 29 ]

这就是我PUT数据的方式:

requests.put("https://www.pipelinedeals.com/...", data={'custom_label_83': [28,29]})

问题似乎是,当我PUT该示例时,我最终只得到29PUT,因为请求(编码后)是这样的:

custom_label_83%5D=28&custom_fields%5D%5Bcustom_label_83%5D=29

因此,该字段被设置两次,最终结果为 29,而不是同时包含 2829 的列表>。我希望 PUT 请求的正文如下所示:

custom_label_83%5D=28,29

我该怎么做?

最佳答案

您遇到的行为(多个 GET 参数)的原因是您将列表作为 params 字典中的键的值传递时的默认 requests 行为.

如果您希望输出为 custom_label_83%5D=28,29,则必须加入列表的值:

>>> ','.join(map(str, [28, 29]))
'28,29'

关于python - 在 Python 请求数据中包含列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22749734/

相关文章:

python - 启动器中的 fatal error : Unable to create process using '"' (even though there are no spaces! )

Python -m http.server 443 - 使用 SSL?

http - 从 Web.py 中的 PUT 方法获取输入

r - 下载图片/png - RCurl

python - Tensorflow:如何平铺按特定顺序重复的张量?

python - 如何在 keras 中实现自定义指标?

python - 附加具有多列索引和重叠列名称的 DataFrames

接收和发出返回值的 Python 协程

python - python init 函数中 master 和 master=none 的用途是什么?

python-2.7 - 使用 Windows Visual Studio 2013 的 Boost 1.55 Python,链接错误