首页 > 解决方案 > Python加密request.post的问题

问题描述

我对加密的发布请求有疑问。加密算法是 AES/ECB/PKCS5Padding,API 设置在这里:https: //bondevalue.com/app/apiInstructions client_token 正在工作。但我总是收到“似乎您提供的输入数据无效。提供有效格式的数据。

import requests
import json
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad, unpad
import base64

client_token = b'ae3rncr14cngemft'
requestData = b'{\"data\":{\"userToken\":\"[ae3rncr14cngemft]\"},\"bondISINId\":\"[XS1401197253]\", \"fromDate\":\"[2016-12-07]\"}'
cipher1 = AES.new(client_token, AES.MODE_ECB)
requestEncrypted = str(base64.b64encode(cipher1.encrypt(pad(requestData, 16, 'pkcs7'))), 'utf-8')

url = 'https://bondevalue.com/app/bondDetailsHistoryData'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
data = {'requestData': requestEncrypted}

answer = requests.post(url=url, data=requestEncrypted, headers=headers)
response = answer.json()

标签: python-3.xapipost

解决方案


推荐阅读