#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from flask_restful import Resource, reqparse, request, Api
from flask import Flask
parser = reqparse.RequestParser()
parser.add_argument("status")

class Recomend_API(Resource):
    def post(self):
        args = parser.parse_args()
        print(args)
        status = args['status']
        print(status)
        result=status+'  and i love python '

        return result

app = Flask(__name__)
api = Api(app)
api.add_resource(Recomend_API, '/')


if __name__ == '__main__':
    app.run()

  • 保存文件micro.py
gunicorn -w 3 -b 127.0.0.1:8000   micro:app
  • 用gunicorn 开多个进程
from requests import put, get,post

response=post('http://127.0.0.1:8000', data={'status': 'I am Thomas'})

print(response.json())
print(response.text)
  • 向服务器发请求
I am Thomas  and i love python 
"I am Thomas  and i love python "
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐