获取ssl.SSLError:[X509]在python中未找到证书或crl(_ssl.c:4062)
我正在使用paho.mqtt库与aws iot core连接,但我无法连接,并且出现以下错误 ssl.SSLError:[X509]未找到证书或crl(_ssl.c:4062) 谁能帮我弄清楚吗获取ssl.SSLError:[X509]在python中未找到证书或crl(_ssl.c:4062),python,amazon-web-services,mqtt,aws-iot,Python,Amazon Web Services,Mqtt,Aws Iot,我正在使用paho.mqtt库与aws iot core连接,但我无法连接,并且出现以下错误 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(c
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...")
将paho.mqtt.client作为paho导入
导入操作系统
导入套接字
导入ssl
从时间上导入睡眠
从随机导入制服
connflag=False
连接上的def(客户端、用户数据、标志、rc):#用于建立连接的func
全球旗帜
打印(“连接到AWS”)
connflag=True
打印(“连接返回结果:+str(rc))
消息上的def(客户端、用户数据、消息):#用于发送消息的Func
打印(msg.topic+“”+str(msg.payload))
mqttc=paho.Client()#mqttc对象
mqttc.on_connect=on_connect#assign on_connect func
mqttc.on_message=on_message#分配on_message func
#mqttc.on_log=on_log
####更改以下参数#####
awshost=“端点”#端点
awsport=8883#端口号。
clientId=“nodemcu”#事物名称
thingName=“nodemcu”#事物名称
caPath=“C:/Users/pc/Desktop/instagram/aws_lambda/certi/public.pem.key”
#根目录\u CA\u证书\u名称
certPath=“C:/Users/pc/Desktop/instagram/aws\u lambda/certi/certificate.pem.crt”
#.cert.pem
keyPath=“C:/Users/pc/Desktop/instagram/aws_lambda/certi/private.pem.key”#
.private.key
mqttc.tls_set(需要caPath、certfile=certPath、keyfile=keyPath、cert_reqs=ssl.cert_、,
tls_version=ssl.PROTOCOL_TLSv1_2,密码=None)#传递参数
mqttc.connect(awshost、awsport、keepalive=60)#连接到aws服务器
mqttc.loop_start()#启动循环
而1==1:
睡眠(5)
如果connflag==True:
温度读数=均匀(20.0,25.0)#产生温度读数
mqttc.publish(“温度”,临时读取,qos=1)#主题:温度#发布
温度值
打印(“发送的消息:温度”+“%.2f”%tempreading)#打印发送的温度消息
安慰
其他:
打印(“等待连接…”)
谢谢,卡帕斯肯定是错的。它需要是Amazon根ca
你可以用谷歌搜索。我通过从中获取最新的Amazon根ca解决了这个问题你在jupyter笔记本中运行代码吗?我用pycharm“ca”表示“证书”?我认为正常的缩写CA代表“证书颁发机构”;)