python max api

# - * - coding: utf- 8 - * - 

Interface Name:
to python3 max
Interface Description:

Interface Address: HTTP: // 127.0.0.1: 8000 / test_max /
Returned Format: JSON
request method: post

Request Parameter (the reference) :
name: name of
age: Age

name required type Description
key is a string full name
qq ID string is the age of

the return parameter descriptions (the reference):

name type Description
ERROR_CODE int returns a status code
reason string returned reasons
result string returned entity content (comprising the)
name string name of the oldest who
age_max maximum string value Age

JSON returned example:

{
"ERROR_CODE": 0, // return a status code
"reason": "Success", // return the reason
"result": {// return entities content
"Data": {
"name": "xiaoming",
"age_max": "18 is",
}
}
}


write rear python code is as follows:
# - * - Coding: UTF-. 8 - * -
Import JSON

DEF max_lgh (http_data):
the try:
http_request_value_list http_data = [ 'Data']
the except Exception AS E:
MSG = 'acquisition failed data {0}' the format (E).
RESPONSE_DATA = { "ERROR_CODE": 500, "reason": "failed", "Message": MSG}
return JSON

# obtain the maximum value of the age, example traditional values: http_request_value_list = [{ 'name': 'Li', 'Age': 24}, { 'name': 'of He', 'Age': 45}]
B = max (http_request_value_list,key=lambda x: x['age'])
response_data = {"error_code": 0,"reason": "success","result": {"data": b}}
# 返回json字符串
json_dump = json.dumps(response_data)
return json_dump


Python代码请求示例:
# -*- coding:UTF-8 -*-
import requests

url = "http://127.0.0.1:8000/test_max/"

par = {"data":
[ {"name": "xiaoming",
"age": "18"
},
{"name": "xiaogan",
"age": "14"
},]
}
r = requests.get(url, params=par)
print(r.text) # returns json, converted into a resolver dictionary r.jsonRES = r.json ()# printing text

# Dictionary to take a field
Conclusion RES = [ "Result"] [ "Data"]
Print (Conclusion)

Guess you like

Origin www.cnblogs.com/lghlxy/p/12202463.html