调用支付宝接口一直出现问题TypeError: ‘tuple‘ object cannot be interpreted as an integer 有没有大佬给瞅一瞅

调用支付宝接口一直报错TypeError: 'tuple' object cannot be interpreted as an integer

 

后端代码:

def order_pay(request):
    if request.method == "POST":
        order_id = request.POST.get('order_id')
        mount = request.POST.get('total_amount')
        # 初始化
        app_private_key_string = open(
            os.path.join(settings.BASE_DIR, 'templates/agriculture/app_private_key.pem')).read(),

        alipay_public_key_string = open(
            os.path.join(settings.BASE_DIR, 'templates/agriculture/alipay_public_key.pem')).read(),
        alipay = AliPay(
            appid="2021000117639272",  # 支付宝沙箱的app id
            app_notify_url=None,  # 默认回调url
            app_private_key_string=app_private_key_string,
            # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
            alipay_public_key_string=alipay_public_key_string,
            sign_type="RSA2",  # RSA 或者 RSA2
            debug=True  # 默认False,沙箱改为True
        )
        # 调用支付接口
        order_string = alipay.api_alipay_trade_page_pay(
            out_trade_no=order_id,  # 订单id
            total_amount=str(mount),  # 支付总金额
            subject="小家惠农在线支付",
            return_url=None,
        )

        # 返回应答
        pay_url = "https://openapi.alipaydev.com/gateway.do" + '?' + order_string
        return HttpResponse(json.dumps({'pay_url': pay_url}))

前端代码:

$(".buy_btn").click(function () {
        $.ajax({
            headers: {"X-CSRFToken": getCookie("csrftoken")},
            url: 'http://127.0.0.1:8000/order_pay',
            type: 'post',
            data:{
                order_id : 20211314520, //订单id
                total_amount  : $('.total').children('em').text()
            },
            success:function (response) {
                var res = JSON.parse(response);
                location.href = res.pay_url
            }
        });

    })

报错:

[25/Apr/2021 18:08:59] "GET /detail/ HTTP/1.1" 200 4441
Internal Server Error: /order_pay
Traceback (most recent call last):
  File "C:\Users\py\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\py\AppData\Local\Programs\Python\Python37\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\graduation_project\weather\views.py", line 242, in order_pay
    debug=True  # 默认False,沙箱改为True
  File "C:\Users\py\AppData\Local\Programs\Python\Python37\lib\site-packages\alipay\__init__.py", line 94, in __init__
    self._load_key()
  File "C:\Users\py\AppData\Local\Programs\Python\Python37\lib\site-packages\alipay\__init__.py", line 99, in _load_key
    self._app_private_key = RSA.importKey(content)
  File "C:\Users\py\AppData\Local\Programs\Python\Python37\lib\site-packages\Cryptodome\PublicKey\RSA.py", line 748, in import_key
    extern_key = tobytes(extern_key)
  File "C:\Users\py\AppData\Local\Programs\Python\Python37\lib\site-packages\Cryptodome\Util\py3compat.py", line 129, in tobytes
    return bytes([s])
TypeError: 'tuple' object cannot be interpreted as an integer

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值