本文整理汇总了Python中urllib2.Request.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python Request.__init__方法的具体用法?Python Request.__init__怎么用?Python Request.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib2.Request
的用法示例。
在下文中一共展示了Request.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, *args, **kwargs):
Request.__init__(self, *args, **kwargs)
logger.info("HTTP request: %s" % args[0])
self.add_header("Cookie", "guid=B11E0A0A522C8371X1378648945")
self.add_header(
"User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X" "10.8; rv:23.0) Gecko/20100101 Firefox/23.0"
)
self.add_header("Accept", "text/html,application/xhtml+xml," "application/xml;q=0.9,*/*;q=0.8")
self.add_header("Accept-Language", "en-us,en;q=0.5")
self.add_header("Accept-Encoding", "gzip,deflate")
self.add_header("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
示例2: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, url, method="GET", headers=None, data=None,
downloadTo=None, closeConnection=False, proxy=None,
redirectedFrom=None, unredirectedHeaders=None, **kw):
"""
"""
headers = headers or dict()
urllib2_Request.__init__(
self, str(url), data=data, headers=headers,
origin_req_host=kw.get("origin_req_host", redirectedFrom),
unverifiable=kw.get("unverifiable", False),
)
Message.__init__(self, url, method, self.headers)
self.host = self._url.host
self.port = self._url.port
self.setProxy(proxy)
assert isinstance(self.headers, util.InsensitiveDict)
unredirectedHeaders = unredirectedHeaders or dict()
self.unredirectedHeaders = util.InsensitiveDict(unredirectedHeaders)
self.closeConnection = closeConnection is True
self.downloadTo = downloadTo
self.redirectedTo = None
self.redirectedFrom = tuple()
self.response = defer.Deferred()
示例3: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, url, data=None, headers=None, origin_req_host=None, unverifiable=False):
'''
Constructor. It delegates construction to the base class
Request and initializes the member variables
It performs an additional call of Request.get_type and Request.get_host
to ensure that the Request object is properly initialized. Because this
is done by the urllib2 library, but we are just using the request
@param url: url to be requested in the HTTP request
@type url: str
@param data: data for the HTTP request body (which enforces a POST)
@type data: str
@param headers: dictionary of header name/header value
@type headers: dict
@param origin_req_host: request host of the origin transaction as per
RFC 2965 - Host name or IP address of the host
@type origin_req_host: str
@param unverifiable: if the request was not verified/requested by the end
user and it is rather automatic (redirection, download
of a picture inside a web page) - RFC 2965
@type unverifiable: bool
'''
if headers is None:
headers = dict()
Request.__init__(self, url, data, headers, origin_req_host, unverifiable)
self.parsed = urlsplit(url)
# Done to force split of the url fields inside the request
self.get_type()
self.get_host()
示例4: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, *args, **kwargs):
Request.__init__(self, *args, **kwargs)
logger.info("HTTP request: %s" % args[0])
self.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; U; '
'Intel Mac OS X 10.5; en-US; rv:1.9.0.1) '
'Gecko/2008070206 Firefox/3.0.1')
self.add_header('Accept', 'text/html,application/xhtml+xml,'
'application/xml;q=0.9,*/*;q=0.8')
self.add_header('Accept-Language', 'en-us,en;q=0.5')
self.add_header('Accept-Encoding', 'gzip,deflate')
self.add_header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')
示例5: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self , url , apiKey , data=None , headers={} ,
origin_req_host=None , unverifiable=False):
if apiKey is not None:
headers['X-Gallery-Request-Key'] = apiKey
if data is not None:
if isinstance(data , dict):
data = 'entity=%s' % quote(json.dumps(data ,
separators=(',' , ':')))
elif type(data) not in types.StringTypes:
raise TypeError('Invalid type for data. It should be '
'a "dict" or "str", not %s' % type(data))
headers['Content-Length'] = str(len(data))
Request.__init__(self , url , data , headers , origin_req_host ,
unverifiable)
示例6: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, url, data = None, headers = {}, version = 'HTTP/1.1'):
self._setupflags()
self._debuglevel = 0
self._response = None
self._cookies = []
self._request_line = None
self._header_producer = None
self._body_producer = None
self._outgoing_producer = None
self._state_listeners = []
_Request.__init__(self, url, None, headers)
self.headers = HeaderDictionary.from_name_value_dict(self.headers)
self._set_version(version)
self.set_data(data)
示例7: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, url, parameters={}, data=None, headers={}, method=None):
if parameters:
parameters = urlencode(parameters)
if method == "POST":
headers["Content-Type"] = "application/x-www-form-urlencoded"
data = parameters.encode('ascii')
else:
url += "?" + parameters
Request.__init__(self, url, data, headers)
self.method = method
self.add_header("Cache-Control", "no-cache")
self.add_header("Pragma", "no-cache")
self.add_header("Accept",
"text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
self.add_header("Connection", "keep-alive")
示例8: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, *args, **kwargs):
self._http_request_method = kwargs.pop("method", "GET")
uRequest.__init__(self, *args, **kwargs)
self.add_header("content-type", "application/json")
示例9: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, url, data='', headers={}):
Request.__init__(self, url, data, headers)
Request.add_header(self, 'User-Agent',
'NilanjanBot(nilanjan-basu.appspot.com/bot/testbot.html)')
示例10: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, *args, **kwargs):
""" Constructor """
self._method = kwargs.pop('method', 'GET')
assert self._method in ['GET', 'POST', 'PUT', 'DELETE']
Request.__init__(self, *args, **kwargs)
示例11: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, *args, **kwargs):
self._method = kwargs.pop('method', None)
_Request.__init__(self, *args, **kwargs)
示例12: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, *args, **kwargs):
self._method = kwargs.get('method')
if self._method:
del kwargs['method']
Request.__init__(self, *args, **kwargs)
示例13: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, method, *args, **kwargs):
URLLibRequest.__init__(self, *args, **kwargs) # ARRGH old-style classes!
self._method = method
示例14: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, method, *args, **kwargs):
self._method = method
Request.__init__(self, *args, **kwargs)
示例15: __init__
# 需要导入模块: from urllib2 import Request [as 别名]
# 或者: from urllib2.Request import __init__ [as 别名]
def __init__(self, method=None, *args, **kwargs):
Request.__init__(self, *args, **kwargs)
self.method = method