python接口调用 get/post

调用Python接口一般有两种方式,get和post
1.get方式调用Python接口
(1)给定具体的参数,进行一次调用

import json
import requests

r = requests.get("http://47.92.225.212:8001/OutCall/recognition?nodeId=6212aea7&query=嗯方便的你说&flowId=1907300015_2&breakTts=0")
print(r.json())

接口调用结果:

{'matchLableData': '你说', 'lableDataToken': {}, 'answerType': 'HIGH_SIMILARITY', 'conditionId': 'g40', 'matchKeywordRegular': '', 'queryToken': {}, 'nodeId': 'fc0f3f20', 'targetNodeId': 'fc0f3f20', 'matchScore': '1', 'titleCondi': '方便', 'actionCode': '', 'matchKeyword': '', 'result': 3}

(2)使用字典构造参数

import json
import requests
nodeId = "6212aea7"
query = "嗯方便的你说"
flowId="1907300015_2"
breakTts="0"
d= {"nodeId":nodeId,"query":query,"flowId":flowId,"breakTts":breakTts}
rr = requests.get("http://47.92.225.212:8001/OutCall/recognition",params = d)
print(rr.json())

接口调用结果:

{'matchLableData': '你说', 'lableDataToken': {}, 'answerType': 'HIGH_SIMILARITY', 'conditionId': 'g40', 'matchKeywordRegular': '', 'queryToken': {}, 'nodeId': 'fc0f3f20', 'targetNodeId': 'fc0f3f20', 'matchScore': '1', 'titleCondi': '方便', 'actionCode': '', 'matchKeyword': '', 'result': 3}

2.post方式调用python接口

import requests
host = "39.98.93.32:10030"
url = "http://"+host+"/debang_text_analysis_model"
body = {"text":{"sentences":[{"speech_rate":252,"emotion_value":5,"begin_time":"0","silence_duration":0,"text":"您好,欢迎致电三大半导体技术,上海有限公司","channel_id":"1","end_time":"5"},{"speech_rate":220,"emotion_value":5,"begin_time":"5","silence_duration":5,"text":"请拨分机号查号,请按0","channel_id":"1","end_time":"8"},{"speech_rate":282,"emotion_value":6,"begin_time":"8","silence_duration":3,"text":"我要看不去,不做伤害,可亏神衰道how's真是纳闷哦ps jung","channel_id":"1","end_time":"15"},{"speech_rate":480,"emotion_value":4,"begin_time":"23","silence_duration":7,"text":"只有朱小姐,我去","channel_id":"2","end_time":"24"},{"speech_rate":120,"emotion_value":6,"begin_time":"28","silence_duration":5,"text":"什么","channel_id":"1","end_time":"29"},{"speech_rate":120,"emotion_value":5,"begin_time":"29","silence_duration":1,"text":"你好","channel_id":"1","end_time":"30"},{"speech_rate":462,"emotion_value":6,"begin_time":"30","silence_duration":0,"text":"喂,你好,哎,你好,我这边是德邦物流公司的,呃,你们那边有一位朱小姐,在我们这里下了一个网站,需要发货是吗?","channel_id":"2","end_time":"37"},{"speech_rate":255,"emotion_value":6,"begin_time":"38","silence_duration":8,"text":"嗯,我们这边应该有同事,已经联系过","channel_id":"1","end_time":"42"},{"speech_rate":240,"emotion_value":5,"begin_time":"42","silence_duration":0,"text":"本公司的","channel_id":"2","end_time":"43"},{"speech_rate":350,"emotion_value":6,"begin_time":"44","silence_duration":1,"text":"你也联系过了对可能已经下单了,对对他是我看到的就是确认你们下的这个订单","channel_id":"2","end_time":"50"},{"speech_rate":400,"emotion_value":6,"begin_time":"51","silence_duration":1,"text":"因为我们看到下订单,就会给客户回电话的。","channel_id":"2","end_time":"54"},{"speech_rate":120,"emotion_value":5,"begin_time":"56","silence_duration":5,"text":"嗯是","channel_id":"1","end_time":"57"},{"speech_rate":220,"emotion_value":6,"begin_time":"58","silence_duration":1,"text":"联系人,就写了个朱小姐","channel_id":"2","end_time":"61"},{"speech_rate":600,"emotion_value":5,"begin_time":"63","silence_duration":5,"text":"对因为刚刚有问过你。","channel_id":"1","end_time":"64"},{"speech_rate":360,"emotion_value":5,"begin_time":"64","silence_duration":0,"text":"我们客服吗?","channel_id":"2","end_time":"65"},{"speech_rate":450,"emotion_value":5,"begin_time":"66","silence_duration":0,"text":"然后他说,你们会给我回电话吗?","channel_id":"2","end_time":"68"},{"speech_rate":340,"emotion_value":5,"begin_time":"68","silence_duration":2,"text":"然后刚刚问我们同事,他说好像是已经","channel_id":"1","end_time":"71"},{"speech_rate":420,"emotion_value":5,"begin_time":"72","silence_duration":4,"text":"叫人来取货了吧","channel_id":"1","end_time":"73"},{"speech_rate":180,"emotion_value":5,"begin_time":"74","silence_duration":0,"text":"啊,今天去取","channel_id":"2","end_time":"76"},{"speech_rate":300,"emotion_value":5,"begin_time":"76","silence_duration":0,"text":"好吧,好吧","channel_id":"2","end_time":"77"}]},"flag":2,"call_ID":"84046_1558682796"}
r = requests.post(url,body)
print(r.status_code)

调用接口返回结果:

200

参考:
https://www.liaoxuefeng.com/wiki/1016959663602400/1183249464292448
https://blog.csdn.net/lihao21/article/details/51857385

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章