【问题标题】:Using python to post a test to API使用 python 将测试发布到 API
【发布时间】:2021-10-14 21:33:25
【问题描述】:
import requests,json

verify='/users/myprofile/Downloads/.me/ca_bundle.crt'

data = {"Authorization": "Basic ODE2YzMzM2ZmYzUwNDg1MThlNTJmMWMyMWJiYzZhOTQ6NWExNDFhMGExNGI4NGQ2OWIyMjUxYTI2OGYwZDJlYjk="}

url = "https://api.pge.com/datacustodian/test/oauth/v2/token?grant_type=client_credentials"

response = requests.post(url, cert=('/users/David/Downloads/bei.me/private.key', data)

#print("status code", response.status_code)

我得到的错误: 文件“SSLTest.py”,第 12 行

                                           ^

SyntaxError: 解析时出现意外的 EOF

在调用公用事业公司的 api 时如何包含我的公共证书?他们让我提交我的公共证书

【问题讨论】:

    标签: python http-post


    【解决方案1】:

    你应该输入:

    response = requests.post(url, cert='/users/David/Downloads/bei.me/private.key', data)
    

    另外:

    公共网站不需要 CA 证书

    PS:你的数据变量看起来像一个标题,所以你可能想要:

    response = requests.post(url, cert='/users/David/Downloads/bei.me/private.key', headers=data)
    

    【讨论】:

    • 它不是一个实际的网站(我的不是)只是一个证书来验证我是谁,当我发帖时说我是谁,它会转到 pge 的网站(他们有我的证书)
    • 谢谢,现在我收到 requests.exceptions.SSLError: HTTPSConnectionPool(host='api.pge.com', port=443): Max retries exceeded with url: /datacustodian/test/oauth/ v2/token?grant_type=client_credentials (由 SSLError(SSLError(9, '[SSL] PEM lib (_ssl.c:3880)')))
    • 使用 cert 关键字将允许 SSL 协议与特定的自建网站一起使用。你不应该把你的私钥放在这里。你可以简单地说:response = requests.post(url, headers=data)
    • PGE 需要证书才能与其 API 进行端到端通信
    猜你喜欢
    • 2019-06-23
    • 2022-11-30
    • 2017-11-02
    • 2013-11-23
    • 1970-01-01
    • 2022-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多