首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >包含证书的Python请求

包含证书的Python请求
EN

Stack Overflow用户
提问于 2020-10-28 09:14:08
回答 1查看 177关注 0票数 0

我正在尝试让汇丰银行开放银行的沙箱工作起来。只有当我禁用-k验证时,他们documentation中的curl命令才会给我一个访问令牌。请注意,我从我的HSBC开发人员dashboard下载了xyz.derserver.key

代码语言:javascript
复制
curl -v -k -X POST \
--cert hsbc/qwac_PSP_PI,PSP_AS,PSP_IC,PSP_AI_27_10_2020.der \
--cert-type DER \
--key hsbc/server.key \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-H "x-fapi-financial-id: test" \
-H "Cache-Control: no-cache" \
-d 'grant_type=client_credentials&scope=accounts&client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer&client_assertion=xyz' \
"https://sandbox.hsbc.com/psd2/obie/v3.1/as/token.oauth2"

由于这是有效的,我正在尝试用requests做同样的事情,但我在如何使用证书上苦苦挣扎。我知道requests支持cert关键字,但似乎我还需要添加其他参数。有没有办法可以指定证书类型和对应的密钥?

代码语言:javascript
复制
import requests

headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Accept": "application/json",
    "x-fapi-financial-id": "test",
    "Cache-Control": "no-cache",
}
params = {
    "grant_type": "client_credentials",
    "scope": "accounts",
    "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    "client_assertion": "xyz",
}
url = "https://sandbox.hsbc.com/psd2/obie/v3.1/as/token.oauth2"

requests.post(url=url,
              headers=headers,
              params=params,
              cert="hsbc/qwac_PSP_PI,PSP_AS,PSP_IC,PSP_AI_27_10_2020.der",
              verify=False).json()
EN

回答 1

Stack Overflow用户

发布于 2020-10-28 09:43:28

感谢@KlausD。在使用openssl.der转换为.pem后,现在可以使用此功能

代码语言:javascript
复制
openssl x509 -inform der -in qwac_xyz.der -out qwac_xyz.pem
代码语言:javascript
复制
import requests

headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Accept": "application/json",
    "x-fapi-financial-id": "test",
    "Cache-Control": "no-cache",
}
params = {
    "grant_type": "client_credentials",
    "scope": "accounts",
    "client_assertion_type": "urn:ietf:params:oauth:client-assertion-type:jwt-bearer",
    "client_assertion": "xyz",
}
url = "https://sandbox.hsbc.com/psd2/obie/v3.1/as/token.oauth2"

requests.post(url=url,
              headers=headers,
              params=params,
              cert=("hsbc/qwac_xyz.pem", "hsbc/server.key"),
              verify=False).json()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64565106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档