python

系统 1543 0

环境spyder(python3.6)

代码:

from flask import Flask, request
import json
import sys
defaultencoding = 'utf-8'
import logging

def tt(name, age):
    result_str = "%s今年%s岁" % (name, age)
    return result_str


app = Flask(__name__)


@app.route("/test_1.0", methods=["GET"])
def check():
    return_dict = {'return_code': '200', 'return_info': '处理成功', 'result': False}
    if request.args is None:
        return_dict['return_code'] = '5004'
        return_dict['return_info'] = '请求参数为空'
        quit()
        return json.dumps(return_dict, ensure_ascii=False)
    get_data = request.args.to_dict()
    name = get_data.get('name')
    age = get_data.get('age')
    return_dict['result'] = tt(name, age)

    return json.dumps(return_dict, ensure_ascii=False)

if __name__ == "__main__":
    app.run("0.0.0.0", port=5000, debug=True)

错误:
  File "E:/NetFramework/Python/app.py", line 43, in
    app.run("0.0.0.0", port=5000, debug=True)

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\flask\app.py", line 938, in run
    cli.show_server_banner(self.env, self.debug, self.name, False)

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\flask\cli.py", line 629, in show_server_banner
    click.echo(message)

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\click \utils.py ", line 260, in echo
    file.write(message)

UnsupportedOperation: not writable

针对上述错误: 定位到D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\click\utils.py的函数echo,将参数file=None,改成file=sys.stdout

 

再次运行出错:
  File "E:/NetFramework/Python/app.py", line 43, in
    app.run("0.0.0.0", port=5000, debug=True)

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\flask\app.py", line 938, in run
    cli.show_server_banner(self.env, self.debug, self.name, False)

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\flask\cli.py", line 636, in show_server_banner
    ' environment.', fg='red')

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\click\ termui.py" , line 420, in secho
    return echo(style(text, **styles), file=file, nl=nl, err=err, color=color)

  File "D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\click\utils.py", line 260, in echo
    file.write(message)

UnsupportedOperation: not writable

针对上述错误: 定位到D:\Soft-win10\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\click\termui.py中的函数secho,将参数file=None,改成file=sys.stdout

修改后,运行成功!!!

 

 


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论