【发布时间】:2017-02-18 12:31:48
【问题描述】:
我想用下面的代码连接到一个rest api:
data = requests.get("http://pbx/rest/login").json()
head = {'loginType' : 'Internal','nonce' : data["nonce"], 'secret' : (hashlib.sha1((LOGIN_ID+data['nonce']+PASSWORD).encode('utf-8')).hexdigest())}
data_new = requests.post('http://pbx/rest/login',data=head)
print(data_new)
从 pbx 请求 nonce 工作正常,然后我需要生成登录密码并将其发布到 pbx,答案应该是令牌
但是 print(data_new) jus 显示我并且 print(data_new.json()) 崩溃并出现以下错误:
Traceback (most recent call last):
File "starface.py", line 14, in <module>
Connect()
File "starface.py", line 12, in Connect
data_new = requests.post(SERVER+"login",data=head).json()
File "C:\Users\BüroNotebook\AppData\Local\Programs\Python\Python35-32\lib\site
-packages\requests\models.py", line 866, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\BüroNotebook\AppData\Local\Programs\Python\Python35-32\lib\json
\__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "C:\Users\BüroNotebook\AppData\Local\Programs\Python\Python35-32\lib\json
\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\BüroNotebook\AppData\Local\Programs\Python\Python35-32\lib\json
\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
【问题讨论】:
标签: python json python-3.x rest python-requests