【发布时间】:2020-04-12 00:58:51
【问题描述】:
我正在尝试使用 Python 和请求将 JSON 内容发布到 API,但我得到了 NameError,因为我的 JSON 包含一个布尔值。
我已经尝试使用 urllib3 并且只是请求并且两者都显示相同的行为。
"enabled": true,
NameError: name 'true' is not defined
我正在 docker 中构建:
FROM python:slim
ADD script.py requirements.txt ./
RUN pip install -r requirements.txt
# Run app.py when the container launches
CMD ["python", "script.py"]
requirements.txt
requests==v2.23.0
urllib3==1.25.8
脚本.py
#import urllib3
import json
resp = req.post('https://example.com/api/endPoint',
json={
"name": "myName",
"rules": [{
"type": "foo",
"enabled": true}]
})
【问题讨论】:
-
试试
True
标签: python json docker python-requests urllib