from flask import Flask, jsonify from PN532data import readChip import webbrowser from threading import Timer from flask import render_template from flask_cors import CORS import string app = Flask(__name__) CORS(app, resources=r'/*') @app.route('/readChip') def read_chip(): try: result = readChip() print(result) return jsonify({'code': 200, 'msg': '读取成功', 'data': {'list': result[0], 'chipNumber': result[1], 'vaccinationCipher': result[2], 'id': result[3]}}) except Exception as e: print(e) return jsonify({'code': 500, 'msg': '请见检查芯片是否放好或读卡器连接是否正常'}) @app.route('/') def index(): return render_template('index.html') def open_browser(): webbrowser.open_new('http://127.0.0.1:9000') if __name__ == '__main__': Timer(1, open_browser).start() app.run(port=9000, debug=True, host='0.0.0.0') # str ="\xc1\xf5\xbf\xad\xcf\xc8\xc9\xfa\r\n\xc9\xed\xb8\xdf\xa3\xba" # str = "this is string example....wow!!!"; # # print(str.decode('utf-8'))