python - 获取 ssl.SSLError: [X509] no certificate or crl found (_ssl.c:4062) in python
问题描述
我正在使用 paho.mqtt 库与 aws iot 核心连接,但我无法连接,并且出现以下错误
ssl.SSLError: [X509] 找不到证书或 crl (_ssl.c:4062)
谁能帮我弄清楚。
import paho.mqtt.client as paho
import os
import socket
import ssl
from time import sleep
from random import uniform
connflag = False
def on_connect(client, userdata, flags, rc): # func for making connection
global connflag
print ("Connected to AWS")
connflag = True
print("Connection returned result: " + str(rc) )
def on_message(client, userdata, msg): # Func for Sending msg
print(msg.topic+" "+str(msg.payload))
mqttc = paho.Client() # mqttc object
mqttc.on_connect = on_connect # assign on_connect func
mqttc.on_message = on_message # assign on_message func
#mqttc.on_log = on_log
#### Change following parameters ####
awshost = "endpoint" # Endpoint
awsport = 8883 # Port no.
clientId = "nodemcu" # Thing_Name
thingName = "nodemcu" # Thing_Name
caPath = "C:/Users/pc/Desktop/instagram/aws_lambda/certi/public.pem.key"
# Root_CA_Certificate_Name
certPath = "C:/Users/pc/Desktop/instagram/aws_lambda/certi/certificate.pem.crt"
# <Thing_Name>.cert.pem
keyPath = "C:/Users/pc/Desktop/instagram/aws_lambda/certi/private.pem.key" #
<Thing_Name>.private.key
mqttc.tls_set(caPath, certfile=certPath, keyfile=keyPath, cert_reqs=ssl.CERT_REQUIRED,
tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None) # pass parameters
mqttc.connect(awshost, awsport, keepalive=60) # connect to aws server
mqttc.loop_start() # Start the loop
while 1==1:
sleep(5)
if connflag == True:
tempreading = uniform(20.0,25.0) # Generating Temperature Readings
mqttc.publish("temperature", tempreading, qos=1) # topic: temperature # Publishing
Temperature values
print("msg sent: temperature " + "%.2f" % tempreading ) # Print sent temperature msg on
console
else:
print("waiting for connection...")
谢谢
解决方案
caPath 肯定是不正确的。它需要是您可以谷歌搜索的亚马逊根 ca。
推荐阅读
- sql - 这两个 SELECT 语句中哪一个是正确的?
- bash - 使用命令“ip”而不是“ifconfig”列出所有 IP
- docker - Windows 主机上的最大文件描述符错误 docker 容器(Windows Server 2019)
- javascript - 根据容器宽度以编程方式设置图像宽度
- openstack - TripleO Openstack 训练自省超时
- azure - 将数据从 ADLS Gen2 加载到 Azure Synapse 时出错
- javascript - postMessage 到父级,父级代码未运行
- ssl - 带有 SSL 的 Apache Kafka 正在工作,但在 kafka 日志中针对本地主机的 SSL 错误(让我发疯)
- javascript - 表单的 ValueChanges 中的 Angular Debounce
- javascript - 如何在 Angular JS (1.6) 驱动的网站中预填充数据时触发手动输入事件