import paho.mqtt.client as mqtt client = mqtt.Client(client_id, transport='tcp') client.username_pw_set(username, password=passwd) 參考: https://www.cnblogs.com/chenpingzhao/p/11383856.html https://www.jianshu.com/p/ef546f476322