当前位置: 首页>>代码示例>>Python>>正文


Python Request.headers['Range']方法代码示例

本文整理汇总了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'
开发者ID:onitu,项目名称:playground,代码行数:38,代码来源:rest_api.py


注:本文中的requests.Request.headers['Range']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。