简体   繁体   English

SSL证书验证在python mqtt连接上失败

[英]SSL Certificate Verify Failed on python mqtt connection

I am a having a very strange issue. 我有一个非常奇怪的问题。 The premise is that I am fairly ignorant in both mqtt and python (the latter I don't use it now since at least 5-6 years), but I am making a Unity app for a museum using a 3D tracking system (www.pozyx.io) and I need each of my machines to run a small mqtt-to-OSC client, so that my Unity app can read the position data from the client. 前提是我在mqtt和python中都相当无知(后者我至少在5 - 6年后才使用它),但我正在使用3D跟踪系统为博物馆制作Unity应用程序(www。 pozyx.io)我需要每台机器运行一个小型的mqtt-to-OSC客户端,以便我的Unity应用程序可以从客户端读取位置数据。

On my development machine, it all works like a charm, using a slightly modified version of the script provided by the sensor producer. 在我的开发机器上,使用传感器生产者提供的脚本的稍作修改的版本,它们的所有工作都像一个魅力。

` `

API_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

import paho.mqtt.client as mqtt
import ssl
import json

from pythonosc.udp_client import SimpleUDPClient


host = "mqtt.cloud.pozyxlabs.com"
port = 443
topic = "5c500595601a3f5871a17685"
username = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

ip = "127.0.0.1"                   # IP for the OSC UDP
network_port = 8888                # network port for the OSC UDP
osc_udp_client = SimpleUDPClient(ip, network_port)


def on_connect(client, userdata, flags, rc):
    print(mqtt.connack_string(rc))


def on_message(client, userdata, msg):

tag_data = json.loads(msg.payload.decode())

for tag in tag_data:
    try:
        network_id = tag["tagId"]
        #print(network_id)
        timestamp = tag["timestamp"]
        position = tag["data"]["coordinates"]
        yaw = tag["data"]["orientation"]["yaw"]

        osc_udp_client.send_message("/position", [network_id, timestamp, position["x"], position["y"], position["z"], yaw])
    except:
        print("Received a bad packet?")
        pass


def on_subscribe(client, userdata, mid, granted_qos):
    print("Subscribed to topic!")


client = mqtt.Client(transport="websockets")

client.username_pw_set(username, password=password)

client.tls_set_context(context=ssl.create_default_context())

client.on_connect = on_connect

client.on_message = on_message
client.on_subscribe = on_subscribe

client.connect(host, port=port)
client.subscribe(topic)

client.loop_forever()

` `

Now that I am in the musem to deploy, of course on the freshly setup windows 10 machines ( I tried both on a NUC and and on a Lenovo Thinkpad), nothing works, and I get each time the following error 现在,我很想部署,当然是在新设置的Windows 10机器上(我在NUC和Lenovo Thinkpad上都尝试过),但没有任何效果,每次出现以下错误

C:\\Users\\Vattenkikare1\\Desktop\\osc_hans>py osc_hans.py Traceback (most recent call last): File "osc_hans.py", line 67, in client.connect(host, port=port) File "C:\\Users\\Vattenkikare1\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\paho\\mqtt\\client.py", line 839, in connect return self.reconnect() File "C:\\Users\\Vattenkikare1\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\paho\\mqtt\\client.py", line 994, in reconnect sock.do_handshake() File "C:\\Users\\Vattenkikare1\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\ssl.py", line 1117, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056) C:\\ Users \\ Vattenkikare1 \\ Desktop \\ osc_hans> py osc_hans.py Traceback(最近一次调用最后一次):文件“osc_hans.py”,第67行,在client.connect(host,port = port)文件“C:\\ Users \\ Vattenkikare1 \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ site-packages \\ paho \\ mqtt \\ client.py“,第839行,在连接中返回self.reconnect()文件”C:\\ Users \\ Vattenkikare1 \\ AppData \\ Local \\ Programs \\ Python \\ Python37-32 \\ lib \\ site-packages \\ paho \\ mqtt \\ client.py“,第994行,重新连接sock.do_handshake()文件”C:\\ Users \\ Vattenkikare1 \\ AppData \\ Local \\程序\\ Python \\ Python37-32 \\ lib \\ ssl.py“,第1117行,在do_handshake self._sslobj.do_handshake()ssl.SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:无法获得本地颁发者证书(_ssl.c :1056)

My laptop is plugged onto the same WiFi and I do have admin rights on all the machines. 我的笔记本电脑已插入同一WiFi,并且我对所有计算机都具有管理员权限。 Would you have any idea on what might be causing the problem? 您对导致问题的原因有任何想法吗? And why might that happen only on the other computers and not on mine? 那为什么只能在其他计算机上而不在我的计算机上发生这种情况呢? I did first deploy an exe to those machines, but then on one of them i did a quick python setup with all the modules, but nothing changed. 我首先在这些机器上部署了一个exe,但是在其中一个机器上,我对所有模块进行了快速python设置,但没有任何改变。

I did find a few similar issues around, but none that I could relate directly to mine in terms of solution. 我确实发现了一些类似的问题,但是就解决方案而言,我没有一个直接与我有关。

I seem to have found the solution in the most random way. 我似乎以最随机的方式找到了解决方案。 I noticed on a post that the Pozyx.io website used the "COMODO RSA Domain Validation Secure Server CA" certificate, and even though the API documentation didn't mention it, I installed it on the test computers and all started working. 我在一篇帖子中注意到Pozyx.io网站使用了“COMODO RSA域验证安全服务器CA”证书,即使API文档没有提及它,我也将它安装在测试计算机上并且一切都开始工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM