发布包含DICS列表的请求数据

发布于 2025-02-12 09:05:23 字数 720 浏览 1 评论 0原文

我试图调用想要一个值列表的API。 我构建一个看起来与此相似的dict:

dataset = { 
  'name': 'somename',
  'note': 'somenote',
  'extras': [{'first': 'entry'}]
}

我将其包括在我的帖子中:

r = requests.post("URL_ENDPOINT", data=dataset, headers=headers)

检查实际数据集字典正确显示了dicts的列表。

{'name': 'somename', 'note': 'somenote', 'extras': [{'spatial': 'test'}]}

但是检查请求对象,r.text

 ... "extras": "first", "type": "dataset"}}, ...

看来dicts的列表正在以某种方式弹出?

I'm trying to call an API that wants a list of dicts for one value.
I build a dict that looks similar to this:

dataset = { 
  'name': 'somename',
  'note': 'somenote',
  'extras': [{'first': 'entry'}]
}

I'm including this in my POST:

r = requests.post("URL_ENDPOINT", data=dataset, headers=headers)

Checking the actual dataset dictionary shows the list of dicts correctly.

{'name': 'somename', 'note': 'somenote', 'extras': [{'spatial': 'test'}]}

But checking the requests object, r.text:

 ... "extras": "first", "type": "dataset"}}, ...

It looks like the list of dicts is being munged in some fashion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔落惊风雨 2025-02-19 09:05:23

尝试注入JSON参数而不是数据

r = requests.post("URL_ENDPOINT", json=dataset, headers=headers)

Try to inject json parameter instead of data

r = requests.post("URL_ENDPOINT", json=dataset, headers=headers)
咽泪装欢 2025-02-19 09:05:23

我远不聪明 - API希望dict使用“键”和“ value”:

我确实尝试了一个JSON软件包,看起来它也可以正常工作。非常感谢!

I’m less than smart - the API wanted the dict to use “key”: and “value”:

I did try a JSOn package and it looks like it would work also. Thank you very much!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文