问题描述
我正在用python开发一个模块,这将允许我将树莓派连接到PC上托管的hivemq版本.
i am developing a module in python that will allow me to connect my raspberry pi to a version of hivemq hosted on my pc.
它正常连接,但是当我添加hivemq的文件auth插件时,它似乎不起作用
it connects normally but when i add hivemq's file auth plugin it doesnt seem to work
我使用username_pw_set设置我的用户名和密码
im using the username_pw_set to set my username and password
这是我的代码当前的样子:
here is what my code currently looks like:
import paho.mqtt.client as mqtt
client = mqtt.Client()
#The callback for when the client recieves a CONNACK response from the server
def on_connect(client, userdata, flags, rc):
print("connected with the result code "+str(rc))
#Define any topics you would like the pi to
#automatically subscribe to here
#The callback for when this client publishes to the server.
def on_publish(client, userdata, mid):
print("message published")
#The callback for when a PUBLISH message is recieve from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
def on_log(client, userdata, level, buf):
print(str(level)+" "+str(buf))
#set callbacks
def setup():
client.on_connect = on_connect
client.on_message = on_message
client.on_publish = on_publish
client.on_log = on_log
#setup connection to broker
def connect(username, password):
client.username_pw_set(username, password)
client.connect("10.19.109.152")
def publish(topic, message):
client.publish(topic, message)
def loop():
client.loop()
这与python客户端格式化连接请求的方式有关吗?
could it be something to do with the way the python client formats the connect request?
服务器给我错误消息:
2015-11-26 09:50:53,723 ERROR - Could not get valid results from the webservice
org.apache.http.NoHttpResponseException: The target server failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(Default
HttpResponseParser.java:143)
和我的客户端(on_connect函数)输出一条代码为5的connack消息,该消息用于未经授权的拒绝连接.
and my client(on_connect function) outputs a connack message with code 5 which is for refused connection as its not authorised.
推荐答案
hivemq出现错误,指出您指向其进行身份验证的http服务器未响应.
The error from hivemq states that the http server you have pointed it at to do the authentication has not responded.
您应该检查那些细节是否正确,以及在使用诸如curl之类的东西进行测试时,它是否能够按预期响应.
You should check that those details are correct and that it responds as expected when you use something like curl to test it.
这篇关于具有HiveMQ的Paho Python客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!