问题描述
我尝试连接到Flask时中断了AWS IoT,但是在连接时,收到消息“客户端断开连接”。
(373178) wsgi starting up on http://0.0.0.0:5000
CLIENT disCONNECTED
(373178) accepted ('127.0.0.1',59162)
127.0.0.1 - - [22/Aug/2020 15:34:53] code 400,message Bad request version ('::\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93JJ\x00\x00\x00\x17\x00\x00ÿ\x01\x00\x01\x00\x00')
127.0.0.1 - - [22/Aug/2020 15:34:53] "üa'=¢hüPáãÇæµWPèò ²Ë@L\È #
½@úA|<TÔöù»`lü ::À+À/À,À0̨̩ÀÀJJÿ" 400 -
(373178) accepted ('127.0.0.1',59164)
127.0.0.1 - - [22/Aug/2020 15:34:53] code 400,message Bad request version ('Q\x8f\x7f\x92\x1a\x02Å\x02\x00"\x1a\x1a\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00')
127.0.0.1 - - [22/Aug/2020 15:34:53] "ü!o×LD(Mu¬µÑ<ÁGµºOÑßIÅô®Ì§ 6Màòæðús»s2TïNëoQÅ"À+À/À,À0̨̩ÀÀ¯>1u´óð
"&e¤O c-² Q鬵07:AÕ¸÷T
ͦJVcîY7,h ÊÊÀ+À/À,À0̨̩ÀÀjjÿ" 400 -
(373178) accepted ('127.0.0.1',59228)
127.0.0.1 - - [22/Aug/2020 15:35:00] code 400,message Bad request version (',\x00"**\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x00')
这是我的代码:
import json
import ssl
from flask import Flask,render_template
import eventlet
from flask_mqtt import Mqtt
from flask_socketio import SocketIO
eventlet.monkey_patch()
app = Flask(__name__)
app.config['SECRET'] = 'my secret key'
app.config['TEMPLATES_AUTO_RELOAD'] = True
# Parameters for SSL
app.config['MQTT_CLIENT_ID'] = "thing"
app.config['MQTT_broKER_URL'] = "a6bxn5zm10lso-ats.iot.us-east-1.amazonaws.com"
app.config['MQTT_TLS_CA_CERTS'] = 'rootca.pem.crt'
app.config['MQTT_TLS_CERTFILE'] = 'certfile.pem.crt'
app.config['MQTT_TLS_KEYFILE'] = 'keyfile.pem.key'
app.config['MQTT_broKER_PORT'] = 8883
app.config['MQTT_KEEPALIVE'] = 60
app.config['MQTT_TLS_ENABLED'] = True
app.config['MQTT_TLS_VERSION'] = ssl.PROTOCOL_TLSv1_2
app.config['MQTT_TLS_CERT_REQS'] = ssl.CERT_required
mqtt = Mqtt(app)
socketio = SocketIO(app)
@app.route('/')
def index():
return render_template('index.html')
# @socketio.on('publish')
# def handle_publish(json_str):
# data = json.loads(json_str)
# mqtt.publish(data['topic'],data['message'])
@socketio.on('subscribe')
def handle_subscribe(json_str):
data = json.loads(json_str)
mqtt.subscribe(data['topic'])
@socketio.on('unsubscribe_all')
def handle_unsubscribe_all():
mqtt.unsubscribe_all()
@mqtt.on_message()
def handle_mqtt_message(client,userdata,message):
data = dict(
topic=message.topic,payload=message.payload.decode()
)
socketio.emit('mqtt_message',data=data)
@mqtt.on_connect()
def handle_connect(client,flags,rc):
print("CLIENT CONNECTED")
@mqtt.on_disconnect()
def handle_disconnect():
print("CLIENT disCONNECTED")
@mqtt.on_log()
def handle_logging(client,level,buf):
print(level,buf)
if __name__ == '__main__':
socketio.run(app,host='0.0.0.0',port=5000,use_reloader=False,debug=True)
我一直找不到答案。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)