Closed. This question is off-topic。它当前不接受答案。
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
2年前关闭。
我有一个我正在处理的项目,我需要,并且我正在尝试发送json请求。我遇到错误,我不知道与我要发送的请求有关的含义。
以下是错误:
这是我尝试发送的请求:
这是回溯,我认为错误将发生在call = call.json()命令所在的位置或它上面带有实际响应的行
想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
2年前关闭。
我有一个我正在处理的项目,我需要,并且我正在尝试发送json请求。我遇到错误,我不知道与我要发送的请求有关的含义。
以下是错误:
JSONDecodeError at /setup_profile/
Expecting value: line 1 column 1 (char 0)
Request Method: POST
Request URL: http://127.0.0.1:8000/setup_profile/
Django Version: 1.8.6
Exception Type: JSONDecodeError
Exception Value:
Expecting value: line 1 column 1 (char 0)
Exception Location: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\scanner.py in _scan_once, line 118
Python Executable: C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\python.exe
Python Version: 3.6.1
Python Path:
['C:\\Users\\OmarJandali\\Desktop\\opentab\\opentab',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\python36.zip',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36',
'C:\\Users\\OmarJandali\\AppData\\Local\\Programs\\Python\\Python36\\lib\\site-packages']
这是我尝试发送的请求:
def createUserSynapse(request):
url = 'http://uat-api.synapsefi.com'
headers = {
'X-SP-GATEWAY' : 'client_id_asdfeavea561va9685e1gre5ara|client_secret_4651av5sa1edgvawegv1a6we1v5a6s51gv',
'X-SP-USER-IP' : '127.0.0.1',
'X-SP-USER' : '| ge85a41v8e16v1a618gea164g65',
'Contant-Type' : 'application/json',
}
payload = {
"logins":[
{
"email":"test@test.com",
}
],
"phone_numbers":[
"123.456.7890",
"test@test.com",
],
"legal_names":[
"Test name",
],
"extras":{
"supp_id":"asdfe515641e56wg",
"cip_tag":12,
"is_business":False,
}
}
print(url)
print(headers)
print(payload)
call = requests.post(url, json=payload, headers=headers)
# response = json.loads(call.text)
call = call.json()
print (call)
print(call.content)
return render(request, 'tabs/create_user_synapse.html', call)
这是回溯,我认为错误将发生在call = call.json()命令所在的位置或它上面带有实际响应的行
Traceback Switch to copy-and-paste view
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) ...
▶ Local vars
C:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in profileSetup
createUserSynapse(request) ...
▶ Local vars
C:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in createUserSynapse
call = call.json() ...
▶ Local vars
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py in json
return complexjson.loads(self.text, **kwargs) ...
▶ Local vars
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\__init__.py in loads
return _default_decoder.decode(s) ...
▶ Local vars
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\decoder.py in decode
obj, end = self.raw_decode(s) ...
▶ Local vars
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\decoder.py in raw_decode
return self.scan_once(s, idx=_w(s, idx).end()) ...
▶ Local vars
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\scanner.py in scan_once
return _scan_once(string, idx) ...
▶ Local vars
C:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\scanner.py in _scan_once
raise JSONDecodeError(errmsg, string, idx) ...
▶ Local vars
最佳答案
您的帖子请求返回b“正在运行!”无法转换为json。所以这行:call = call.json()引发JSONDecodeError错误。
关于python - JSONDecodeError期望值:第1行第1列(字符0),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46045026/