Hi Pythonanywhere fellows,
I'd like to subscribe to a TheThingsNetwork topic using the MQTT API: https://www.thethingsindustries.com/docs/integrations/mqtt/
The Api works fine for me using the paho-mqtt client: https://pypi.org/project/paho-mqtt/ My code looks as follows:
import context
import paho.mqtt.subscribe as subscribe
import time
import re
import json
while True:
m = subscribe.simple(topics=['#'], hostname="eu1.cloud.thethings.network", port=1883, auth={'username':"mycrazyusername@ttn",'password':"mycrazypw"}, msg_count=2)
for a in m:
payload = json.loads(a.payload)
print(payload)
I am receiving following error that relates to the socks module:
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/subscribe.py", line 262, in simple
callback(_on_message_simple, topics, qos, userdata, hostname, port,
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/subscribe.py", line 174, in callback
client.connect(hostname, port, keepalive)
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 941, in connect
return self.reconnect()
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 1075, in reconnect
sock = self._create_socket_connection()
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3533, in _create_socket_connection
proxy = self._get_proxy()
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3494, in _get_proxy
if self._proxy_is_valid(self._proxy):
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3483, in _proxy_is_valid
return check(p.get("proxy_type"), p.get("proxy_addr"))
File "/home/Markovicz/.local/lib/python3.8/site-packages/paho/mqtt/client.py", line 3480, in check
t in set([socks.HTTP, socks.SOCKS4, socks.SOCKS5]) and a)
AttributeError: module 'socks' has no attribute 'HTTP'
Do you have any ideas how to fix that?
This error has previously been reported here: https://www.pythonanywhere.com/forums/topic/27492/