TypeError: __init__() got an unexpected keyword argument app_private_key_path解决

(python3.7) appleyuchi@ubuntu19:django_alipay_insert$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.

March 02, 2020 - 08:46:39
Django version 2.2.10, using settings 'django_alipay_insert.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[02/Mar/2020 08:46:44] "GET / HTTP/1.1" 200 1159
Internal Server Error: /pay/
Traceback (most recent call last):
  File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/appleyuchi/桌面/Django接入支付宝/django_alipay_insert/payments/views.py", line 31, in pay
    debug=True  # 默认False  配合沙箱模式使用
TypeError: __init__() got an unexpected keyword argument 'app_private_key_path'
Internal Server Error: /check_pay/
Traceback (most recent call last):
  File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/appleyuchi/桌面/Django接入支付宝/django_alipay_insert/payments/views.py", line 64, in check_pay
    debug=True  # 默认False  配合沙箱模式使用
TypeError: __init__() got an unexpected keyword argument 'app_private_key_path'
[02/Mar/2020 08:46:45] "POST /pay/ HTTP/1.1" 500 17458
[02/Mar/2020 08:46:45] "GET /check_pay/?order_id=2016101400682827 HTTP/1.1" 500 17370

 

略难解决...

(python3.7) appleyuchi@ubuntu19:~$ python -c "import alipay;print(alipay)"
<module 'alipay' from '/home/appleyuchi/.virtualenvs/python3.7/lib/python3.7/site-packages/python_alipay_sdk-2.0.1-py3.7.egg/alipay/__init__.py'>
根据[1]我们知道:

这个python蛋就是一个类似于jar的东西,里面都是二进制,那就没法打开来看,

有点难啊...怎么办呢?

最终解决方案:

>>> import inspect
>>> from alipay import AliPay
>>> inspect.getsource(AliPay)
'class AliPay(BaseAliPay):\n    pass\n'
>>> inspect.getargspec(AliPay)
__main__:1: DeprecationWarning: inspect.getargspec() is deprecated since Python 3.0, use inspect.signature() or inspect.getfullargspec()
ArgSpec(args=['self', 'appid', 'app_notify_url', 'app_private_key_string', 'alipay_public_key_string', 'sign_type', 'debug'], varargs=None, keywords=None, defaults=(None, None, 'RSA2', False))

上面加粗的就是我们需要的

 

所以故障原因是:

这个第三方sdk升级版本后,入口参数的名字被改动了。

 

所以最终解决方案:

①app_private_key_path改成app_private_key_string

②alipay_public_key_path改成alipay_public_key_string

③同时原先给变量(app_private_key_path/alipay_public_key_path)赋值的是秘钥文件名

现在需要给变量(app_private_key_string/alipay_public_key_string)赋值的是的是秘钥的文件中的内容。

 

Reference:

[1]https://stackoverflow.com/questions/2051192/what-is-a-python-egg

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值