SoFunction
Updated on 2024-12-13

Python-flask call interface to return Chinese data problems

Python-flaskCalling the interface to return Chinese data

code block

from flask import Flask,jsonify
from flask import render_template
 
import pymssql
app = Flask(__name__)
 
 
 
@('/')
def index():
    conn = (server=".", user="sa", password="123456", database="cz", charset="GBK")
    cur = ()
    sql = "select * from GL_Czrz"
    (sql)
    u= ()
    data=u[0]
    ()
    return jsonify({"station": data[0], "no": data[1], "name": data[2], "date": data[3], "zwrq": data[4], "qssj": data[5],"zzsj": data[6], "cznr": data[7], "CZNRKZ": data[8]})
 
 
if __name__ == '__main__':
    ['JSON_AS_ASCII'] = False
    (debug=True, port=5051)
        #(host='0.0.0.0',debug=True)
# This will allow the OS to listen to all public IPs #
#If you're using Flask-Script, you'll have problems with the above, so you'll need to add the following to the runserver's py file, in a more aesthetically pleasing location.
#manager.add_command('runserver', Server(host='0.0.0.0'))

Results Showcase

summarize

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.