def DELETE(fname, address): #print fname + ', DELETE' res = requests.delete(address, prefetch=True) try: res.raise_for_status( ) # raise exception if som comunication error occured except Exception as e: print str(e) return res.json
def operations_log_DELETE(pp): print "operations/log, DELETE" res = requests.delete('http://localhost/istsos/wa/istsos/operations/log', prefetch=True) pp.pprint(res.json) try: res.raise_for_status( ) # raise exception if som comunication error occured except Exception as e: print str(e) print "\n ************************************ \n"
def services_name_DELETE(pp): print "services/{name}, DELETE" dbname = "test_update" res = requests.delete('http://localhost/istsos/wa/istsos/services/' + dbname, prefetch=True) try: res.raise_for_status( ) # raise exception if som comunication error occured except Exception as e: print str(e) pp.pprint(res.json) print "\n ************************************ \n"
def services_name_dataqualities_code_DELETE(pp): print "services/{name}/dataqualities/{code}, DELETE" dbname = "demo" qualcode = '42' res = requests.delete('http://localhost/istsos/wa/istsos/services/' + dbname + '/dataqualities/' + qualcode, prefetch=True) try: res.raise_for_status( ) # raise exception if som comunication error occured except Exception as e: print str(e) pp.pprint(res.json) print "\n ************************************ \n"
def services_name_configsections_provider_DELETE(pp): print "services/{name}/configsections/provider, DELETE" #shouldn't work with default as {name} dbname = 'default' res = requests.delete('http://localhost/istsos/wa/istsos/services/' + dbname + '/configsections/provider', prefetch=True) pp.pprint(res.json) try: res.raise_for_status( ) # raise exception if som comunication error occured except Exception as e: print str(e) print "\n ************************************ \n"
def services_name_observedproperties_name_DELETE(pp): print "services/{name}/observedproperties/{name}, DELETE" dbname = "demo" oname = 'urn:ogc:def:parameter:x-istsos:1.0:meteo:air:LoveIsInTheAir' res = requests.delete('http://localhost/istsos/wa/istsos/services/' + dbname + '/observedproperties/' + oname, prefetch=True) try: res.raise_for_status( ) # raise exception if som comunication error occured except Exception as e: print str(e) pp.pprint(res.json) print "\n ************************************ \n"
def _request(method, path, params={}, json_body={}): url = TMDB.url + '/' + path + '?api_key=' + TMDB.api_key if method == 'GET': headers = {'Accept': 'application/json'} content = requests.get(url, params=params, headers=headers, verify=False).content elif method == 'POST': for key in params.keys(): url += '&' + key + '=' + params[key] headers = {'Content-Type': 'application/json', \ 'Accept': 'application/json'} content = requests.post(url, data=json.dumps(json_body), headers=headers, verify=False).content elif method == 'DELETE': for key in params.keys(): url += '&' + key + '=' + params[key] headers = {'Content-Type': 'application/json', \ 'Accept': 'application/json'} content = requests.delete(url, data=json.dumps(json_body), headers=headers, verify=False).content else: raise Exception('method: ' + method + ' not supported.') response = json.loads(content.decode('utf-8')) return response
def request(self, method, resource, headers=None, stream=None, data=None, files=None, timeout=60): ''' #===================================================================== # @Method: 进行RESTful接口的HTTP请求 # @Param: method, 为HTTP Method,如 :'GET', 'POST', 'DELETE' 等 # resource, 请求的RESTful资源路径 # data,可选参数,请求Body部分携带的数据,dict类型 # headers, 可选参数,请求Header携带的数据,dict类型 # tmout,可选参数,http操作的超时时间,默认为10秒; # @Return: 正常,返回response对象;异常,返回None。 # @author: #===================================================================== ''' # If the user sets the timeout parameter and passes the check, # the user timeout is set. # Otherwise, the default value is used. if self.timeout is not None: timeout = self.timeout if headers is None: if self.headerhost is not None: headers = {'X-Auth-Token': self.token, 'If-Match': self.etag, 'Host': self.headerhost} else: headers = {'If-Match': self.etag} if type(data) is dict: payload = json.dumps(data) else: payload = data if self.port is not None: url = r'https://%s:%d%s' % (self.host, self.port, resource) else: url = r'https://%s%s' % (self.host, resource) try: if method == 'POST': r = requests.post(url, data=payload, files=files, headers=headers, auth=self.auth, verify=False, timeout=timeout) elif method == 'GET': r = requests.get(url, data=payload, headers=headers, auth=self.auth, verify=False, timeout=timeout) elif method == 'DELETE': r = requests.delete(url, data=payload, headers=headers, auth=self.auth, verify=False, timeout=timeout) elif method == 'PATCH': r = requests.patch(url, data=payload, headers=headers, auth=self.auth, verify=False, timeout=timeout) else: sys.exit(127) except Exception as dummy_e: print('Failure: failed to establish a new connection to the host') sys.exit(127) if r.status_code == 401: self.err_401_proc(r) sys.exit(145) elif r.status_code == 403: if files is not None: print('Failure: insufficient privilege or server is doing another request') else: print('Failure: you do not have the required permissions to ' + 'perform this operation') sys.exit(147) elif r.status_code == 500: print('Failure: the request failed due to an internal ' + 'service error') sys.exit(244) elif r.status_code == 501: print('Failure: the server did not support the functionality ' + 'required') sys.exit(245) elif r.status_code == 409: error_info_check(r) sys.exit(153) elif r.status_code == 405: print('Failure: A request was made of a resource using a request method not supported by that resource.') sys.exit(149) else: return r