I did a test here now with this code:
import paho.mqtt.client as mqtt
api_key='your key here'
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, reason_code, properties):
print(f"Connected with result code {reason_code}")
client.subscribe("6/obj/test")
def on_message(client, userdata, msg):
print(msg.payload)
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
mqttc.tls_set()
mqttc.username_pw_set(username="token-is-used", password=api_key)
mqttc.connect("lynx.iotopen.se", 8883)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.loop_forever()
You obviously have to change the key and the topic.