python - 蝗虫-Python-ssl.SSLError : [SSL] PEM lib (_ssl. c:4065)

标签 python ssl python-requests locust http.client

我是 python 和 locust 的新手,尝试运行我的第一个 locust perf 脚本来测试 API
但是,我收到错误 ssl.SSLError: [SSL] PEM lib (_ssl.c:4065)
对于以下代码。

class MyHttpTest(HttpUser):
wait_time = constant(5)
host = "https://abc.myorg.net"
headers = {
    'Content-Type': "application/json",
    'Ocp-Apim-Trace': "true",
    'Ocp-Apim-Subscription-Key': "<APIM subscription Key>",
    'Cache-Control': "no-cache"
}
payload = "{\n\t\"name\": \"abc\"\n}"

@task
def get_status(self):

    self.client.headers = self.headers
    self.client.verify = False

    self.client.post("/uam/Link/Get/v1", data=self.payload,
                     cert=("<path to pfx certificate>",
                           "<password of pfx certificate"))

最佳答案

检查这些:
How to configure Locust to use https?
What does "SSLError: [SSL] PEM lib (_ssl.c:2532)" mean using the Python ssl library?
很确定问题出在您尝试用作证书的 .pfx 文件上。 Locust 的 HttpUser 的客户端是基于 Requests 的。我目前找不到任何说请求可以直接使用 .pfx 文件的内容。您需要具有 .cert 或 .pem 格式。我还没有尝试过,但我发现一个要点说它可以让你使用 .pfx 和 Requests 所以它应该可以与 Locust 一起工作,我想。
https://gist.github.com/erikbern/756b1d8df2d1487497d29b90e81f8068

关于python - 蝗虫-Python-ssl.SSLError : [SSL] PEM lib (_ssl. c:4065),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69611314/

相关文章:

python - 如何在 Django 选择字段中实现位掩码

python - 导入错误 : No module named 'requests'

python - 如何在 python 中使用 wordpress REST api 上传图像?

ssl - visual studio无情提示信任IIS Express SSL证书

php - 使用 cURL 或 socket_create 发送自定义 HTTP POST 请求

ssl - Cloudera Manager软件升级到最新版本

python-requests - django-silk 显示所有查询的时间为 0

python - 卡在 Celery 队列中的任务

python - 将归一化标量颜色图应用于 matplotlib 图,仍然获得默认颜色

python - OpenCV 差异输出没有意义