执行interface_AES_test.py的时候result = r.json()会报错
wongyee11 opened this issue · 3 comments
ERROR: test_aes_interface (main.AESTest)
test aes interface
Traceback (most recent call last):
File "G:/PycharmProjects/Django/guest-master/tests/interface_AES_test.py", line 39, in test_aes_interface
result = r.json()
File "D:\Anaconda3\lib\site-packages\requests\models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "D:\Anaconda3\lib\json_init_.py", line 354, in loads
return _default_decoder.decode(s)
File "D:\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
不知道问题出在哪里,代码都比对过了,就是不行
安装pycryptodomex后,更改为from Cryptodome.Cipher import AES,再次运行后报错:
ERROR: test_aes_interface (main.AESTest)
test aes interface
Traceback (most recent call last):
File "G:/PycharmProjects/Django/guest-master/tests/interface_AES_test.py", line 37, in test_aes_interface
encoded = self.encryptAES(json.dumps(payload), self.app_key).decode()
File "G:/PycharmProjects/Django/guest-master/tests/interface_AES_test.py", line 27, in encryptAES
cryptor = AES.new(key, AES.MODE_CBC, iv)
File "D:\Anaconda3\lib\site-packages\Cryptodome\Cipher\AES.py", line 232, in new
return create_cipher(sys.modules[name], key, mode, *args, **kwargs)
File "D:\Anaconda3\lib\site-packages\Cryptodome\Cipher_init.py", line 79, in _create_cipher
return modes[mode](factory, **kwargs)
File "D:\Anaconda3\lib\site-packages\Cryptodome\Cipher_mode_cbc.py", line 274, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File "D:\Anaconda3\lib\site-packages\Cryptodome\Cipher\AES.py", line 103, in _create_base_cipher
result = start_operation(c_uint8_ptr(key),
File "D:\Anaconda3\lib\site-packages\Cryptodome\Util_raw_api.py", line 145, in c_uint8_ptr
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code
修改了两行代码:
self.app_key = str.encode('W7v4D60fds2Cmk2U')
ciphertext = cryptor.encrypt(str.encode(self.pad(src)))
再次运行报错和未更改库之前一样:
Traceback (most recent call last):
File "G:/PycharmProjects/Django/guest-master/tests/interface_AES_test.py", line 46, in test_aes_interface
result = r.json()
File "D:\Anaconda3\lib\site-packages\requests\models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "D:\Anaconda3\lib\json_init_.py", line 354, in loads
return _default_decoder.decode(s)
File "D:\Anaconda3\lib\json\decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
望看到后可以帮忙解答一下,代码是按照书和GitHub里对比过的,未改动。
这书感觉坑贼多