MOOC (7) - case dependent, the configuration file is read json plurality of interface requests - Request Interface Package (1)

 

 
 
Package interface request # 
Import Requests
Import JSON


DEF send_get (URL, para):
RES = requests.get (URL, para)
return res.json ()


DEF send_post (URL, Data):
RES = requests.post (URL, Data)
res.json = r ()
# json.dumps json such that the output data dictionary or more beautiful, where the parameter r may be a dictionary, can be json
return json.dumps (r, indent = 2, sort_keys = True, False = ensure_ascii )


DEF run_main (URL, Method, Data = None):
RES = None
IF method.upper () == "the GET":
RES = send_get (URL, Data)
elif method.upper () == "the POST":
RES = send_post (url, the Data)
the else:
Print ( "Please enter the correct parameters")
return RES


URL_1 = "HTTP: //apis.juhe.cn/rubbish/search"
data = {"key": "6d9cc6b16d6cf63caded401b99c7311e",
"q": "奶茶",
"type": 1}
r = run_main(url_1, "post", data)
print(r)

 

Guess you like

Origin www.cnblogs.com/come202011/p/12313080.html
Recommended