def connect():
with open(‘emqxsl-ca.crt’, ‘rb’) as f:
cadata = f.read()
ssl_params = dict()
ssl_params[“cert_reqs”] = ssl.CERT_REQUIRED
ssl_params[“cadata”] = cadata
ssl_params[“server_hostname”] = SERVER
client = MQTTClient(CLIENT_ID, SERVER, PORT, USERNAME, PASSWORD, ssl = True, ssl_params = ssl_params)
client.connect()
print(‘Connected to MQTT Broker “{server}”’.format(server = SERVER))
return client
这里为什么报TypeError: unexpected keyword argument 'ssl_params’这个错误,类型不对吗
一般是因为你使用的client API 因为版本不同,支持的参数有变化引起的。可以使用老一点的client版本,或者查阅client的文档确定新版本的用法。