我在AWS服务器上运行MQTT代理,该代理在Mac上正常运行,而Windows设备在树莓派上无法正常运行。我的订阅者和发布者代码有效,并且已经在多个操作系统上进行了测试。我相信问题出在我的树莓派设置上,但是我无法解决。
我收到的错误(使用python3):
pi@raspberrypi:~/MQTT $ sudo python3 subscriber.py
Traceback (most recent call last):
File "subscriber.py", line 42, in <module>
client.connect(brokerAddress,port,60)
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 937, in connect
return self.reconnect()
File "/usr/local/lib/python3.7/dist-packages/paho/mqtt/client.py", line 1100, in reconnect
sock.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)
我通过python收到的错误,
pi@raspberrypi:~/MQTT $ python subscriber.py
Traceback (most recent call last):
File "subscriber.py", line 42, in <module>
client.connect(brokerAddress,port,60)
File "/home/pi/.local/lib/python2.7/site-packages/paho/mqtt/client.py", line 937, in connect
return self.reconnect()
File "/home/pi/.local/lib/python2.7/site-packages/paho/mqtt/client.py", line 1100, in reconnect
sock.do_handshake()
File "/usr/lib/python2.7/ssl.py", line 828, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:727)
我尝试了几件事,包括使用python vs python3,确保安装了最新版本的paho,重新启动,在另一个网络上运行raspberry pi,以sudo身份运行,以及其他一些事情。
这可能无关紧要,但之前在此树莓派上尝试运行git clone时遇到了问题,我认为这可能与ssl问题有关。
其他可能有用的东西
pi@raspberrypi:~/MQTT $ openssl version
OpenSSL 1.1.1d 10 Sep 2019
代码Subscriber.py:
import paho.mqtt.client as mqtt
import sys
import time
import ssl
# The callback for when the client receives a conack response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("test")
printf("subscribed to test")
# When a message is received
def on_message(client, userdata, msg):
print("INCOMING") #begin message
print("TOPIC: \t\t"+msg.topic+"\nMESSAGE:\t"+str(msg.payload.decode()))
client = mqtt.Client("C1")
#declare loc of tls certificate
client.tls_set('/home/pi/MQTT/ca.crt',cert_reqs=ssl.CERT_NONE)
client.tls_insecure_set(True)
client.on_connect = on_connect
client.on_message = on_message
#plain text credentials
client.username_pw_set("myusername","mypassword")
#declare address and port
brokerAddress="my-ipv4-ip-address"
port=8883
client.connect(brokerAddress,port,60)
#continuous loop
client.loop_forever()
在Mac上运行时,此确切代码有效,我可以从桌面(Windows)发布此消息,并按预期显示。
如果您需要我提供其他任何信息来帮助进行故障排除,请务必告诉我。
答案 0 :(得分:0)
我遇到了同样的问题。
我生成的证书是TLSv1.0证书。但是默认情况下,RPi的openssl配置不接受这些设置。
我通过将可接受的最低协议版本从v1.2更改为v1.0来解决了这个问题
在/etc/ssl/openssl.cnf
中
将MinProtocol = TLSv1.2
更改为MinProtocol = TLSv1.0