以下是我正在执行的用于发帖请求并收到此错误的代码
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())
答案 0 :(得分:0)
您的链接没有域:http://autobot###/_search/api/v1.0/
。
如果写入.com
和response.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>