本文整理汇总了Python中pycurl.HEADER属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.HEADER属性的具体用法?Python pycurl.HEADER怎么用?Python pycurl.HEADER使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.HEADER属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_curl_for_post
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def setup_curl_for_post(c, p, data_buf, headers=None, share=None):
setup_curl_basic(c, p, data_buf, headers, share)
httpheader = p.get('httpheader', ['Accept: application/json', "Content-type: application/json"])
if httpheader:
# c.setopt(pycurl.HEADER, p.get('header', 1))
c.setopt(pycurl.HTTPHEADER, httpheader)
post301 = getattr(pycurl, 'POST301', None)
if post301 is not None:
# Added in libcurl 7.17.1.
c.setopt(post301, True)
c.setopt(pycurl.POST, 1)
postfields = p.get('postfields')
if postfields:
postfields = json.dumps(postfields, indent=2, ensure_ascii=False)
c.setopt(pycurl.POSTFIELDS, postfields)
return c
示例2: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def request(self, endpoint, headers=None, post=None, first=True):
buffer = BytesIO()
ch = pycurl.Curl()
ch.setopt(pycurl.URL, endpoint)
ch.setopt(pycurl.USERAGENT, self.userAgent)
ch.setopt(pycurl.WRITEFUNCTION, buffer.write)
ch.setopt(pycurl.FOLLOWLOCATION, True)
ch.setopt(pycurl.HEADER, True)
if headers:
ch.setopt(pycurl.HTTPHEADER, headers)
ch.setopt(pycurl.VERBOSE, self.debug)
ch.setopt(pycurl.SSL_VERIFYPEER, False)
ch.setopt(pycurl.SSL_VERIFYHOST, False)
ch.setopt(pycurl.COOKIEFILE, self.settingsPath + self.username + '-cookies.dat')
ch.setopt(pycurl.COOKIEJAR, self.settingsPath + self.username + '-cookies.dat')
if post:
import urllib
ch.setopt(pycurl.POST, len(post))
ch.setopt(pycurl.POSTFIELDS, urllib.urlencode(post))
ch.perform()
resp = buffer.getvalue()
header_len = ch.getinfo(pycurl.HEADER_SIZE)
header = resp[0: header_len]
body = resp[header_len:]
ch.close()
if self.debug:
import urllib
print("REQUEST: " + endpoint)
if post is not None:
if not isinstance(post, list):
print('DATA: ' + urllib.unquote_plus(json.dumps(post)))
print("RESPONSE: " + body + "\n")
return [header, json_decode(body)]
示例3: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def request(self, endpoint, post=None):
buffer = BytesIO()
ch = pycurl.Curl()
ch.setopt(pycurl.URL, Constants.API_URL + endpoint)
ch.setopt(pycurl.USERAGENT, self.userAgent)
ch.setopt(pycurl.WRITEFUNCTION, buffer.write)
ch.setopt(pycurl.FOLLOWLOCATION, True)
ch.setopt(pycurl.HEADER, True)
ch.setopt(pycurl.VERBOSE, False)
ch.setopt(pycurl.COOKIEFILE, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat"))
ch.setopt(pycurl.COOKIEJAR, os.path.join(self.IGDataPath, self.username, self.username + "-cookies.dat"))
if post is not None:
ch.setopt(pycurl.POST, True)
ch.setopt(pycurl.POSTFIELDS, post)
if self.proxy:
ch.setopt(pycurl.PROXY, self.proxyHost)
if self.proxyAuth:
ch.setopt(pycurl.PROXYUSERPWD, self.proxyAuth)
ch.perform()
resp = buffer.getvalue()
header_len = ch.getinfo(pycurl.HEADER_SIZE)
header = resp[0: header_len]
body = resp[header_len:]
ch.close()
if self.debug:
print("REQUEST: " + endpoint)
if post is not None:
if not isinstance(post, list):
print("DATA: " + str(post))
print("RESPONSE: " + body)
return [header, json_decode(body)]
示例4: connect
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def connect(self, host, port, scheme):
fp = pycurl.Curl()
fp.setopt(pycurl.SSL_VERIFYPEER, 0)
fp.setopt(pycurl.SSL_VERIFYHOST, 0)
fp.setopt(pycurl.HEADER, 1)
fp.setopt(pycurl.USERAGENT, 'Mozilla/5.0')
fp.setopt(pycurl.NOSIGNAL, 1)
return TCP_Connection(fp)
示例5: setup_curl_for_get
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def setup_curl_for_get(c, p, data_buf, headers=None, share=None):
setup_curl_basic(c, p, data_buf, headers, share)
httpheader = p.get('httpheader')
if httpheader:
# c.setopt(pycurl.HEADER, p.get('header', 1))
c.setopt(c.HTTPHEADER, httpheader)
return c
示例6: getPage
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def getPage (self, url, requestHeader = []) :
resultFormate = StringIO.StringIO()
fakeIp = self.fakeIp()
requestHeader.append('CLIENT-IP:' + fakeIp)
requestHeader.append('X-FORWARDED-FOR:' + fakeIp)
try:
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url.strip())
curl.setopt(pycurl.ENCODING, 'gzip,deflate')
curl.setopt(pycurl.HEADER, 1)
curl.setopt(pycurl.TIMEOUT, 120)
curl.setopt(pycurl.SSL_VERIFYPEER, 0)
curl.setopt(pycurl.SSL_VERIFYHOST, 0)
curl.setopt(pycurl.HTTPHEADER, requestHeader)
curl.setopt(pycurl.WRITEFUNCTION, resultFormate.write)
curl.perform()
headerSize = curl.getinfo(pycurl.HEADER_SIZE)
curl.close()
header = resultFormate.getvalue()[0 : headerSize].split('\r\n')
body = resultFormate.getvalue()[headerSize : ]
except Exception, e:
header = ''
body = ''
示例7: head
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def head(self):
conn=pycurl.Curl()
conn.setopt(pycurl.SSL_VERIFYPEER,False)
conn.setopt(pycurl.SSL_VERIFYHOST,1)
conn.setopt(pycurl.URL,self.completeUrl)
conn.setopt(pycurl.HEADER, True) # estas dos lineas son las que importan
conn.setopt(pycurl.NOBODY, True) # para hacer un pedido HEAD
conn.setopt(pycurl.WRITEFUNCTION, self.header_callback)
conn.perform()
rp=Response()
rp.parseResponse(self.__performHead)
self.response=rp
示例8: test_request_head
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def test_request_head(self):
curl = pycurl.Curl()
curl.setopt = MagicMock()
curl.perform = MagicMock()
curl.getinfo = MagicMock(return_value=200)
curl.close = MagicMock()
pycurl.Curl = MagicMock(return_value=curl)
method = 'head'
url = 'http://localhost:4502/.cqactions.html'
params = {'foo1': 'bar1', 'foo2': ['bar2a', 'bar2b']}
handlers = {200: self._handler_dummy}
result = pyaem.bagofrequests.request(method, url, params, handlers)
curl.setopt.assert_any_call(pycurl.HEADER, True)
curl.setopt.assert_any_call(pycurl.NOBODY, True)
curl.setopt.assert_any_call(pycurl.URL, 'http://localhost:4502/.cqactions.html')
curl.setopt.assert_any_call(pycurl.FOLLOWLOCATION, 1)
curl.setopt.assert_any_call(pycurl.FRESH_CONNECT, 1)
# 6 calls including the one with pycurl.WRITEFUNCTION
self.assertEqual(curl.setopt.call_count, 6)
curl.perform.assert_called_once_with()
curl.getinfo.assert_called_once_with(pycurl.HTTP_CODE)
curl.close.assert_called_once_with()
self.assertEqual(result.is_success(), True)
self.assertEqual(result.message, 'some dummy message')
self.assertEqual(result.response['request']['method'], 'head')
self.assertEqual(result.response['request']['url'], 'http://localhost:4502/.cqactions.html')
self.assertEqual(result.response['request']['params'], params)
示例9: request
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import HEADER [as 别名]
def request(method, url, params, handlers, **kwargs):
"""Sends HTTP request to a specified URL.
Parameters will be appended to URL automatically on HTTP get method.
Response code will then be used to determine which handler should process the response.
When response code does not match any handler, an exception will be raised.
:param method: HTTP method (post, delete, get)
:type method: str
:param url: URL to send HTTP request to
:type url: str
:param params: Request parameters key-value pairs, use array value to represent multi parameters with the same name
:type params: dict
:param handlers: Response handlers key-value pairs, keys are response http code, values are callback methods
:type handlers: dict
:returns: PyAemResult -- Result of the request containing status, response http code and body, and request info
:raises: PyAemException
"""
curl = pycurl.Curl()
body_io = cStringIO.StringIO()
if method == 'post':
curl.setopt(pycurl.POST, 1)
curl.setopt(pycurl.POSTFIELDS, urllib.urlencode(params, True))
elif method == 'delete':
curl.setopt(pycurl.CUSTOMREQUEST, method)
elif method == 'head':
curl.setopt(pycurl.HEADER, True)
curl.setopt(pycurl.NOBODY, True)
else:
url = '{0}?{1}'.format(url, urllib.urlencode(params, True))
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.FRESH_CONNECT, 1)
curl.setopt(pycurl.WRITEFUNCTION, body_io.write)
curl.perform()
response = {
'http_code': curl.getinfo(pycurl.HTTP_CODE),
'body': body_io.getvalue(),
'request': {
'method': method,
'url': url,
'params': params
}
}
curl.close()
if response['http_code'] in handlers:
return handlers[response['http_code']](response, **kwargs)
else:
handle_unexpected(response, **kwargs)