json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

搭建微服务后调用报错:json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

报错详细:
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)_第1张图片
原代码:

import numpy as np
import requests

url = 'http://127.0.0.1:8010/predictCustom'
headers = {'Content-Type': 'application/json'}
data = np.random.random([32, 10, 4])
parm_map = {"data": data}
r = requests.post(url, headers=headers, data=parm_map)
result = r.json()
print(result)

安装demjson包:pip install demjson -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

修改后代码:

import numpy as np
import requests
import demjson
import json

url = 'http://127.0.0.1:8010/predictCustom'
headers = {'Content-Type': 'application/json'}
data = np.random.random([32, 10, 4])
parm_map = {"data": data}
r = requests.post(url, headers=headers, data=parm_map)
# result = r.json()
# print(result)
rr=demjson.encode(r, encoding='utf-8')
hh=json.loads(rr)
print(hh)

你可能感兴趣的:(报错Bug解决方法,python,数据挖掘,深度学习)