烧瓶:在要求中通过JSON中的布尔值

发布于 2025-02-13 13:51:58 字数 265 浏览 0 评论 0原文

使用Python 请求库,我如何在请求主体中发送布尔值?我已经尝试过:

request_body = {'somebooleanvalue':true}。 =>名称:名称'true'未定义

request_body = {'somebooleanvalue':true} =>只有Unicode对象是可以逃脱的。 type< class“ bool”>。

谢谢!

Using the Python requests library, how can I send a boolean value in request body? I've tried:

request_body = {'someBooleanValue': true}. => NameError: name 'true' is not defined

request_body = {'someBooleanValue': True} => Only unicode objects are escapable. Got True of type <class 'bool'>.

Thanks!

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

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

发布评论

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

评论(1

睫毛上残留的泪 2025-02-20 13:51:59

您可以在请求方法中的json参数中传递带有布尔值的字典:

def request(self, method, url,
            params=None, data=None, headers=None, cookies=None, files=None,
            auth=None, timeout=None, allow_redirects=True, proxies=None,
            hooks=None, stream=None, verify=None, cert=None, json=None):

您也可以在此处执行json = request_body

,我看不到烧瓶与这个问题有什么关系 - 请求库是一个单独的python库,而不是与烧瓶。让我知道我是否在这里误解了一些东西。

you can pass the dictionary with boolean values as the json parameter in the request method:

def request(self, method, url,
            params=None, data=None, headers=None, cookies=None, files=None,
            auth=None, timeout=None, allow_redirects=True, proxies=None,
            hooks=None, stream=None, verify=None, cert=None, json=None):

you can do json=request_body here

Also, I dont see what flask has to do with this question - the requests library is a separate python library and not related to flask. Let me know if I misunderstood something here.

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