0
我想用下面的代码连接到一个REST API:的Python连接到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只是正常工作,那么我需要生成登录秘密,有权发布它的PBX和答案应该是一个令牌
但打印(data_new)强制显示我和打印(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)