Closed YuG0819 closed 2 years ago
(venv) PS D:\DEVELOPPROJECTS\PythonProject\data_analysis> python .\wechatpay.py
Traceback (most recent call last):
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\wechatpayv3\utils.py", line 73, in load_private_key
return load_pem_private_key(data=format_private_key(private_key_str).encode('UTF-8'), password=None, backend=default_backend())
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\cryptography\hazmat\primitives\serialization\base.py", line 22, in load_pem_private_key
return ossl.load_pem_private_key(data, password)
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 900, in load_pem_private_key
return self._load_key(
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 1168, in _load_key
self._handle_key_loading_error()
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 1227, in _handle_key_loading_error
raise ValueError(
ValueError: ('Could not deserialize key data. The data may be in an incorrect format, it may be encrypted with an unsupported algorithm, or it may be an unsupported key type (e.g. EC c
urves with explicit parameters).', [_OpenSSLErrorWithText(code=503841036, lib=60, reason=524556, reason_text=b'error:1E08010C:DECODER routines::unsupported'), _OpenSSLErrorWithText(cod
e=109052072, lib=13, reason=168, reason_text=b'error:068000A8:asn1 encoding routines::wrong tag'), _OpenSSLErrorWithText(code=109576458, lib=13, reason=524554, reason_text=b'error:0688
010A:asn1 encoding routines::nested asn1 error')])
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".\wechatpay.py", line 46, in <module>
wxpay = WeChatPay(
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\wechatpayv3\__init__.py", line 38, in __init__
self._core = Core(mchid=self._mchid,
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\wechatpayv3\core.py", line 20, in __init__
self._private_key = load_private_key(private_key)
File "D:\DEVELOPPROJECTS\PythonProject\data_analysis\venv\lib\site-packages\wechatpayv3\utils.py", line 75, in load_private_key
raise Exception('failed to load private key.')
Exception: failed to load private key.
商户证书私钥格式不对。
PRIVATE_KEY我只直接复制的私钥字符串
请问应该传什么格式的数据?
# 商户证书私钥
with open('path_to_key/apiclient_key.pem') as f:
PRIVATE_KEY = f.read()
Exception: failed to load private key.
python 运行出错,请问是什么问题