Can use Google Chrome postman to implement Interface simulation request
Default rules for function pass parameters:
Use*argsand the**kwPython is a customary way of writing, of course, you can use other parameter names, but it is best to use idioms.
1 GET Request
#通过api获取json返回值的, a general function
Def op_on_api (u, method= ' GET ', **kw): url = u r = requests.get (url, params=kw, timeout=10) if r.status_code != 200: raise exception (' CORE API cannot process this URL: ' + url + ' request! return code: ' + str (R.status_code) + ' \n\tmessage:{' + r.content + '} ' + ' \n\tdata:==\n ' + str (args) + ' \n== ') &nBsp; return r.json ()
GET request print r.url You can know the URL of the specific parameter of the request, which is HTTP just oh
U ' http://youapi?key2=value2&key1=value1 '
2 POST Request
import os,json, requests url = "Http://youapi" payload={ "Key1": "Value1", "Key2": "value2",}headers = {' Content-type ': ' Application/json '}r = Requests.post (Url, data=json.dumps (payload), headers=headers,timeout=10)
This article is from the "Tridewah operation and maintenance work Road" blog, please be sure to keep this source http://cuidehua.blog.51cto.com/5449828/1783991
Requests module Common functions