pythonanywher 上的 paho-mqtt 身份验证错误
paho-mqtt authentication error on pythonanywher
我正在尝试在 beebotte.com 上使用简单的 publish.single
在我的 linux 机器上发布到一个 mqtt 主题,它工作正常但是在 python 任何地方我得到一个授权错误。小版本号有细微差别,难道是什么不同?
这是我输入 python 控制台的代码:
import paho.mqtt.publish as publish
mqtt_host = "beebotte.com"
mqtt_topic = "climate/set/livingroom"
auth = {'username':"token:MY_SECRET_TOKEN"}
publish.single(mqtt_topic, "python sent", hostname=mqtt_host, auth = auth)
这是错误:
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import paho.mqtt.publish as publish
>>> mqtt_host = "beebotte.com"
>>> mqtt_topic = "climate/set/livingroom"
>>> auth = {'username':"MY_SECRET_TOKEN"}
>>> publish.single(mqtt_topic, "python sent", hostname=mqtt_host, auth = auth)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/publish.py", line 216, in single
protocol, transport)
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/publish.py", line 152, in multiple
client.connect(hostname, port, keepalive)
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 895, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
>>>
>>> exit()
它正在运行:
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import paho.mqtt.publish as publish
>>> mqtt_host = "beebotte.com"
>>> mqtt_topic = "climate/set/livingroom"
>>> auth = {'username':"MY_SECRET_TOKEN"}
>>> publish.single(mqtt_topic, "python sent", hostname=mqtt_host, auth = auth)
>>>
>>> exit()
编辑(我不确定这是不是真的):
密钥采用 token:token_KxDxlcmXgQBDfWRNC
的实际格式(不是真实的) beebotte.com 也接受格式为 2A4Gfgv0puYFBEVbBQX24szALcyDvMRh
的所谓密钥 如果我使用密钥,它可以从 python任何地方(有时)。这让我相信这是令牌中 :
的某种格式问题。
所以现在的问题是如何格式化才能正常工作。
我认为 mqtt 无法通过 PythonAnywhere 上的免费帐户运行。免费帐户只能使用 http(s) 通过代理连接到特定的网站白名单。如果某处有一个 http 到 mqtt 桥,你可以使用它。
我正在尝试在 beebotte.com 上使用简单的 publish.single
在我的 linux 机器上发布到一个 mqtt 主题,它工作正常但是在 python 任何地方我得到一个授权错误。小版本号有细微差别,难道是什么不同?
这是我输入 python 控制台的代码:
import paho.mqtt.publish as publish
mqtt_host = "beebotte.com"
mqtt_topic = "climate/set/livingroom"
auth = {'username':"token:MY_SECRET_TOKEN"}
publish.single(mqtt_topic, "python sent", hostname=mqtt_host, auth = auth)
这是错误:
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import paho.mqtt.publish as publish
>>> mqtt_host = "beebotte.com"
>>> mqtt_topic = "climate/set/livingroom"
>>> auth = {'username':"MY_SECRET_TOKEN"}
>>> publish.single(mqtt_topic, "python sent", hostname=mqtt_host, auth = auth)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/publish.py", line 216, in single
protocol, transport)
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/publish.py", line 152, in multiple
client.connect(hostname, port, keepalive)
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/home/<MYUSER>/python-email/local/lib/python2.7/site-packages/paho/mqtt/client.py", line 895, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
>>>
>>> exit()
它正在运行:
Python 2.7.13 (default, Nov 24 2017, 17:33:09)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import paho.mqtt.publish as publish
>>> mqtt_host = "beebotte.com"
>>> mqtt_topic = "climate/set/livingroom"
>>> auth = {'username':"MY_SECRET_TOKEN"}
>>> publish.single(mqtt_topic, "python sent", hostname=mqtt_host, auth = auth)
>>>
>>> exit()
编辑(我不确定这是不是真的):
密钥采用 token:token_KxDxlcmXgQBDfWRNC
的实际格式(不是真实的) beebotte.com 也接受格式为 2A4Gfgv0puYFBEVbBQX24szALcyDvMRh
的所谓密钥 如果我使用密钥,它可以从 python任何地方(有时)。这让我相信这是令牌中 :
的某种格式问题。
所以现在的问题是如何格式化才能正常工作。
我认为 mqtt 无法通过 PythonAnywhere 上的免费帐户运行。免费帐户只能使用 http(s) 通过代理连接到特定的网站白名单。如果某处有一个 http 到 mqtt 桥,你可以使用它。