import requests
import json
data = {"texts": '{"uuid": [5, 1], "createName": ["小王", "小王"], "location": ["sdsdsdsd号", "sdsfssf"], "eventTime": ["2020/10/1 14:46", "2020/10/1 14:46"], "content": ["你的师傅师傅v","所得税方式!!!"], "type": ["房地产项目","房地产项目"]}'}
url = "http://127.0.0.1:5000/nlp/v1/texts_dict"
res = requests.post(url=url, data=data)
text = res.text
print(text)#原始JSON类型文件
import json
from flask import Flask, request, jsonify
from gevent import pywsgi
from flask_restful import reqparse, Api, Resource
from Intelligent_warning import IntelligentWarning
app = Flask(__name__)
app.config["JSON_AS_ASCII"] = False
app.config.update(RESTFUL_JSON=dict(ensure_ascii=False))
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument('texts')
def post(self):
args = parser.parse_args()
texts = json.loads(args['texts'])
result_new_list_json = IntelligentWarning().early_warning(texts)
return {'result': result_new_list_json}, 201
api.add_resource(TextIntelligentWarning, '/nlp/v1/texts_dict')
if __name__ == '__main__':
app.run(debug=True)
注意以上传输是以参数+值的形式传输,并且参数对应的值一定是json格式,收到之后再进行转换,用的flask_restful
import requests
import json
data={"uuid": [5,1], "createName": ["小王","小王"], "location": ["大哥大哥大哥","地方的蛋糕"], "eventTime": ["2020/10/1 14:46","2020/10/1 14:46"], "content": ["大幅度发","大富大贵"], "type": ["房地产项目","房地产项目"]}
url = "http://127.0.0.1:5000/nlp/v1/texts_dict"
headers = {"Content-type": "application/json"}
r = requests.post(url=url, headers=headers, data=json.dumps(data))
print(json.dumps(r.json(), indent=4, ensure_ascii=False))
from flask import Flask, request, jsonify
from flask.views import MethodView
from Intelligent_warning import IntelligentWarning
app = Flask(__name__)
class TextIntelligentWarning(MethodView):
def post(self):
texts = request.get_json()
result_new_list_json = IntelligentWarning().early_warning(texts)
return jsonify({'code': 200, 'msg': 'ok', 'data': result_new_list_json})
app.add_url_rule('/nlp/v1/texts_dict', view_func=TextIntelligentWarning.as_view(name='texts_dict'))
if __name__ == "__main__":
app.run()
以上这种方式不需要关注参数,直接全部接收即可,用电flask
ymysql报错:cryptography is required for sha256_password or caching_sha2_password
这段报错意思是说 sha256_password 和 caching_sha2_password 这两个加密算法需要用到 cryptography 。虽然意思很明了,但是可能不知道如何解决。
其实 cryptography 是一个python包,所以解决方法很简单:
$ pip install cryptography
1
完事。