python - Python HTTP POST JSON 错误,在变量中发送 base64
问题描述
我试图将 base64 图像发布到现有服务,但是当我将变量(img)添加到请求正文时,我收到错误:JSONDecodeError:期望值:第 1 行第 1 列(字符 0)
import requests
img = base64.encodebytes(open
('/x/b51ad9ac-b648-40ce-ac7b-ce0c7a6af65b.jpeg',
'rb').read())#.decode('utf-8')
newHeaders = {'Content-type': 'application/json'}
response = requests.post('http://127.0.0.1/api/cv/pdm/outer/v2/',
data={'caseId': '123123123',
'partNo': 'bumper',
'imageName': 'hz.jpeg',
'imageData': img,
'timestamp': '1596610139236'}, headers=newHeaders)
print("Status code: ", response.status_code)
response_Json = response.json()
print(response_Json)
print("Content-Type is ", response_Json)
怎么了?提前致谢
JSONDecode 期间的完整异常日志
*Status code: 413
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-82-7cc8a2bb1cf2> in <module>
20 print("Status code: ", response.status_code)
21
---> 22 response_Json = response.json()
23
24 print(response_Json)
~/opt/anaconda3/lib/python3.7/site-packages/requests/models.py in json(self, **kwargs)
895 # used.
896 pass
--> 897 return complexjson.loads(self.text, **kwargs)
898
899 @property
~/opt/anaconda3/lib/python3.7/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
~/opt/anaconda3/lib/python3.7/json/decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
~/opt/anaconda3/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)*
解决方案
推荐阅读
- javascript - 如何让 Google 脚本在特定行的特定范围内隐藏特定列中带有空格或零的行?
- html - 如何在Angular中检查长度
- c++ - 我应该创建一个类对象吗?
- javascript - 如何在数组中拆分内部数组?
- c# - 为什么当我选择多个文件时,IFormfile 只将第一个文件转换为字节?
- c - 为什么这个内核会导致问题?
- python - 您可以像使用 SBOP Analysis for Excel 一样使用 Python 连接到 SAP Query 吗?
- azerothcore - 已经有现有的 MariaDB docker 容器 - 我如何编译 world 和 auth 服务器以使用它而不是构建 db 容器
- python - 在函数末尾使用 return 1 或 -1 有什么必要?
- certificate - 签署证书问题