本文整理汇总了Python中pycurl.HTTPGET属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.HTTPGET属性的具体用法?Python pycurl.HTTPGET怎么用?Python pycurl.HTTPGET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.HTTPGET属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_getter
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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
示例2: perform_fp
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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()
示例3: send_REST_request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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
示例4: send_REST_request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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
示例5: send_REST_request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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
示例6: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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)
示例7: send_REST_request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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
示例8: send_REST_request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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
示例9: get
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HTTPGET [as 别名]
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)