我在Safaricom上实现了利帕na M-Pesa,但是,当我请求时,我收到一个错误消息,说检测到重复的json密钥。
有效载荷:
payload = {
"BusinessShortCode": 174379,
"Password": "the password",
"Timestamp": "20220817050503",
"TransactionType": "CustomerPayBillOnline",
"Amount": 5,
"PartyA": 254714895622,
"PartyB": 174379,
"PhoneNumber": 254714895622,
"CallBackURL": "https://58fa-102-68-78-50.in.ngrok.io/api/v1/payments/callback/",
"AccountReference": "Payment",
"TransactionDesc": "Payment for K"
}
标题:
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer access_token",
}
请求:
response = requests.request("POST", 'https://sandbox.safaricom.co.ke/mpesa/stkpush/v1/processrequest', headers=headers, data=payload)
我得到的回答是:
{
'responseId': '82699-21939686',
'responseCode': '400',
'responseDesc': 'Duplicate json key detected'
}
这个错误的原因可能是什么?我该如何解决它?
3条答案
按热度按时间jdgnovmf1#
问题出在标头中,请求默认传递
Content-Type
,删除它修复了问题。8gsdolmq2#
虽然在Safaricom的Python的M-pesa Daraja代码示例中提供了它,但请尝试更改此部分以使其成为;将
body=payload
重命名为json=payload
代替
按照建议从头文件中删除
Content-Type
给了我另一个错误;对我有用,希望对你有用
myss37ts3#
以下工程