Python pycurl.HTTPGET Examples
The following are 10
code examples of pycurl.HTTPGET().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pycurl
, or try the search function
.
Example #1
Source File: smgr_status.py From contrail-server-manager with Apache License 2.0 | 6 votes |
def send_REST_request(ip, port, object, match_key, match_value, detail): try: response = StringIO() headers = ["Content-Type:application/json"] url = "http://%s:%s/%s" % (ip, port, object) args_str = '' if match_key: args_str += match_key + "=" + match_value if detail: args_str += "&detail" if args_str != '': url += "?" + args_str conn = pycurl.Curl() conn.setopt(pycurl.URL, url) conn.setopt(pycurl.HTTPHEADER, headers) conn.setopt(pycurl.HTTPGET, 1) conn.setopt(pycurl.WRITEFUNCTION, response.write) conn.perform() return response.getvalue() except: return None # end def send_REST_request
Example #2
Source File: smgr_contrail_status.py From contrail-server-manager with Apache License 2.0 | 6 votes |
def send_REST_request(ip, port, object, match_key, match_value, detail): try: response = StringIO() headers = ["Content-Type:application/json"] url = "http://%s:%s/%s" % (ip, port, object) args_str = '' if match_key: args_str += match_key + "=" + match_value if detail: args_str += "&detail" if args_str != '': url += "?" + args_str conn = pycurl.Curl() conn.setopt(pycurl.TIMEOUT, 1) conn.setopt(pycurl.URL, url) conn.setopt(pycurl.HTTPHEADER, headers) conn.setopt(pycurl.HTTPGET, 1) conn.setopt(pycurl.WRITEFUNCTION, response.write) conn.perform() return response.getvalue() except: return None # end def send_REST_request
Example #3
Source File: smgr_monitoring.py From contrail-server-manager with Apache License 2.0 | 6 votes |
def send_REST_request(self, server_ip, port): try: response = StringIO() headers = ["Content-Type:application/json"] url = "http://%s:%s/%s" % (server_ip, port, 'MonitorInfo') args_str = '' conn = pycurl.Curl() conn.setopt(pycurl.URL, url) conn.setopt(pycurl.HTTPHEADER, headers) conn.setopt(pycurl.HTTPGET, 1) conn.setopt(pycurl.WRITEFUNCTION, response.write) conn.perform() data_dict = response.getvalue() data_dict = dict(json.loads(data_dict)) data_list = list(data_dict["__ServerMonitoringInfoTrace_list"]["ServerMonitoringInfoTrace"]) return data_list except Exception as e: print "Error is: " + str(e) return None # end def send_REST_request
Example #4
Source File: patator_ext.py From project-black with GNU General Public License v2.0 | 6 votes |
def perform_fp(fp, method, url, header='', body=''): #logger.debug('perform: %s' % url) fp.setopt(pycurl.URL, url) if method == 'GET': fp.setopt(pycurl.HTTPGET, 1) elif method == 'POST': fp.setopt(pycurl.POST, 1) fp.setopt(pycurl.POSTFIELDS, body) elif method == 'HEAD': fp.setopt(pycurl.NOBODY, 1) else: fp.setopt(pycurl.CUSTOMREQUEST, method) headers = [h.strip('\r') for h in header.split('\n') if h] fp.setopt(pycurl.HTTPHEADER, headers) fp.perform()
Example #5
Source File: http_client.py From pledgeservice with Apache License 2.0 | 5 votes |
def request(self, method, url, headers, post_data=None): s = util.StringIO.StringIO() curl = pycurl.Curl() if method == 'get': curl.setopt(pycurl.HTTPGET, 1) elif method == 'post': curl.setopt(pycurl.POST, 1) curl.setopt(pycurl.POSTFIELDS, post_data) else: curl.setopt(pycurl.CUSTOMREQUEST, method.upper()) # pycurl doesn't like unicode URLs curl.setopt(pycurl.URL, util.utf8(url)) curl.setopt(pycurl.WRITEFUNCTION, s.write) curl.setopt(pycurl.NOSIGNAL, 1) curl.setopt(pycurl.CONNECTTIMEOUT, 30) curl.setopt(pycurl.TIMEOUT, 80) curl.setopt(pycurl.HTTPHEADER, ['%s: %s' % (k, v) for k, v in headers.iteritems()]) if self._verify_ssl_certs: curl.setopt(pycurl.CAINFO, os.path.join( os.path.dirname(__file__), 'data/ca-certificates.crt')) else: curl.setopt(pycurl.SSL_VERIFYHOST, False) try: curl.perform() except pycurl.error, e: self._handle_request_error(e)
Example #6
Source File: client.py From pycopia with Apache License 2.0 | 5 votes |
def get_getter(self): """Initialze a Curl object for a single GET request. Returns a tuple of initialized Curl and HTTPResponse objects. """ c = pycurl.Curl() resp = HTTPResponse(self._encoding) c.setopt(pycurl.HTTPGET, 1) if self._query: self._url.query.update(self._query) self._query = None c.setopt(c.URL, str(self._url)) c.setopt(c.WRITEFUNCTION, resp._body_callback) c.setopt(c.HEADERFUNCTION, resp._header_callback) c.setopt(c.HTTPHEADER, map(str, self._headers)) self._set_common(c) return c, resp
Example #7
Source File: smgr_show.py From contrail-server-manager with Apache License 2.0 | 5 votes |
def send_REST_request(ip, port, rest_api_params, detail): try: response = StringIO() headers = ["Content-Type:application/json"] url = "http://%s:%s/%s" % (ip, port, rest_api_params['object']) args_str = '' if rest_api_params["select"]: args_str += "select" + "=" \ + urllib.quote_plus(rest_api_params["select"]) + "&" if rest_api_params["match_key"]: args_str += urllib.quote_plus(rest_api_params["match_key"]) + "=" \ + urllib.quote_plus(rest_api_params["match_value"]) if rest_api_params['object'] == 'log' and rest_api_params["file_key"]: args_str += "&" + urllib.quote_plus(rest_api_params["file_key"]) + "=" \ + urllib.quote_plus(rest_api_params["file_value"]) if 'show_passwords' in rest_api_params: args_str += "&show_pass=true" if detail: args_str += "&detail" if args_str != '': url += "?" + args_str conn = pycurl.Curl() conn.setopt(pycurl.URL, url) conn.setopt(pycurl.HTTPHEADER, headers) conn.setopt(pycurl.HTTPGET, 1) conn.setopt(pycurl.WRITEFUNCTION, response.write) conn.perform() return response.getvalue() except: return None # end def send_REST_request
Example #8
Source File: smgr_add.py From contrail-server-manager with Apache License 2.0 | 5 votes |
def send_REST_request(ip, port, object, payload, match_key=None, match_value=None, detail=False, method="PUT"): try: args_str = "" response = StringIO() headers = ["Content-Type:application/json"] if method == "PUT": url = "http://%s:%s/%s" %( ip, port, object) elif method == "GET": url = "http://%s:%s/%s" % (ip, port, object) if match_key: args_str += match_key + "=" + match_value if detail: args_str += "&detail" if args_str != '': url += "?" + args_str else: return None conn = pycurl.Curl() conn.setopt(pycurl.URL, url) conn.setopt(pycurl.HTTPHEADER, headers) if method == "PUT": conn.setopt(pycurl.POST, 1) conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload)) conn.setopt(pycurl.CUSTOMREQUEST, "PUT") elif method == "GET": conn.setopt(pycurl.HTTPGET, 1) conn.setopt(pycurl.WRITEFUNCTION, response.write) conn.perform() return response.getvalue() except: return None
Example #9
Source File: __init__.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def get(self, url="", params=None): "Ship a GET request for a specified URL, capture the response." if params: url += "?" + urllib_parse.urlencode(params) self.set_option(pycurl.HTTPGET, 1) return self.__request(url)
Example #10
Source File: patator.py From patator with GNU General Public License v2.0 | 4 votes |
def perform_fp(fp, method, url, header='', body=''): #logger.debug('perform: %s' % url) fp.setopt(pycurl.URL, url) if method == 'GET': fp.setopt(pycurl.HTTPGET, 1) elif method == 'POST': fp.setopt(pycurl.POST, 1) fp.setopt(pycurl.POSTFIELDS, body) elif method == 'HEAD': fp.setopt(pycurl.NOBODY, 1) else: fp.setopt(pycurl.CUSTOMREQUEST, method) headers = [h.strip('\r') for h in header.split('\n') if h] fp.setopt(pycurl.HTTPHEADER, headers) fp.perform()