API数据传输,flask发送接收两种方式/cryptography is required for sha256_password or caching_sha2_password

291 篇文章 2 订阅
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
完事。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值