本文整理汇总了Python中requests.Request.headers['Range']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers['Range']方法的具体用法?Python Request.headers['Range']怎么用?Python Request.headers['Range']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.Request
的用法示例。
在下文中一共展示了Request.headers['Range']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from requests import Request [as 别名]
# 或者: from requests.Request import headers['Range'] [as 别名]
def get(self, args, bytes_range=''):
"""Downloads a remote file. It is a two-step process:
first acquire the metadatas on the API, then download the actual content of the file from the Files address."""
url = U1Driver.BASE_API_PATH
url += '/~/' if not args[0].startswith('/~/') else ''
url += urllib2.quote(args[0])
req = Request('GET', url)
print 'Sending request to', url
try:
rep = self.oauth_signed_request(req)
except requests.exceptions.HTTPError as httpe:
print httpe, "upon access to", url
return
metadatas = rep.json()
url = U1Driver.BASE_FILES_PATH + urllib2.quote(metadatas.get('content_path'), safe="/")
req = Request('GET', url)
if bytes_range != '':
req.headers['Range'] = 'bytes=' + bytes_range
print 'Downloading contents of', url
try:
rep = self.oauth_signed_request(req)
except requests.exceptions.HTTPError as httpe:
print httpe, "while downloading", url
return
content = rep.content
try:
local_filename = args[1]
except IndexError:
local_filename = args[0].split('/')[-1]
print 'Writing contents to', local_filename
try:
with open(local_filename, 'wb') as local_file:
local_file.write(content)
except IOError:
print "Unable to write to file", local_filename
print 'Done'