烧瓶API的错误JSONDecodeError(“期望值”,s,err.value)无json.decoder.JSONDecodeError:期望值:第1行第1列(字符0)

时间:2020-06-05 03:39:50

标签: python api flask

以下是我正在执行的用于发帖请求并收到此错误的代码

JSONDecodeError(“期望值”,s,err.value)从无 json.decoder.JSONDecodeError:预期值:第1行第1列(字符 0)错误

import requests,json
request_data = {"files": ["\\r\\tabs\\lg\\supp\\p\\tabrvstring\\TStringManager.h @ 118",
               "\\qt\\VION\\localbase\\base\\kernel\\qobject.cpp @ 1418"]}

response = requests.post('http://autobot/_search/api/v1.0/',
                         headers = {'Content-Type':'application/json'},data = json.dumps(request_data))

print("Status code: ", response.status_code)
print("Printing Entire Post Request")
print(response.json())

1 个答案:

答案 0 :(得分:0)

您的链接没有域:http://autobot###/_search/api/v1.0/

如果写入.comresponse.json(),则会引发相同的错误。因为response没有json数据。尝试断点或print(response.text)

要从文本转换为json,请使用json.loads(response.text)

import requests, json
request_data = {"files": ["\\r\\tabs\\lg\\supp\\p\\tabrvstring\\TStringManager.h @ 118",
               "\\qt\\VION\\localbase\\base\\kernel\\qobject.cpp @ 1418"]}

url = 'http://autobot.com/_search/api/v1.0/'
headers = {'Content-Type':'application/json'}
data = json.dumps(request_data)
response = requests.post(url, headers = headers, data = data)

print("Status code: ", response.status_code)
print("Printing Entire Post Request")
#print(response.json())
print(response.text)

# Status code:  200
# Printing Entire Post Request
# <html><head><title>autobot.com</title></head><body><h1>autobot.com</h1><p>Coming soon.</p></body></html>