Error with flask API JSONDecodeError("Expecting value", s, err.value) None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Viewed 1240

Below is the code I'm executing for post request and getting this error

JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) error

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 Answers

Your link doesn't have domain: http://autobot###/_search/api/v1.0/.

If write .com and response.json() the same error raised. Because response doesn't have json data. Try to breakpoint or print(response.text).

For convert from text to json use 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>
Related