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


Python ZipFile.raise_for_status方法代码示例

本文整理汇总了Python中zipfile.ZipFile.raise_for_status方法的典型用法代码示例。如果您正苦于以下问题:Python ZipFile.raise_for_status方法的具体用法?Python ZipFile.raise_for_status怎么用?Python ZipFile.raise_for_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zipfile.ZipFile的用法示例。


在下文中一共展示了ZipFile.raise_for_status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from zipfile import ZipFile [as 别名]
# 或者: from zipfile.ZipFile import raise_for_status [as 别名]
# Open the wanted_accessions file and read in each accession, stripping newline
# characters, and adding each accesion into the list accession_ids
accession_IDs = []
with open(wanted_accessions, "r") as accessions:
    accessions_list = accessions.readlines()
    for line in accessions_list:
        line = line.rstrip()
        accession_IDs.append(line)
# Join each accession id into a string seperated by '+' characters for URL
# construction below
gene_IDs = "+".join(accession_IDs)

# Construct the URL with wanted accessions, Example URL:
# http://iptol-api.iplantcollaborative.org/onekp/v1/orthogroups?
# accession=AT4G04640+AT1G15700+AT4G09650+AT2G07707+AT4G32260
# &token=1463695387322_wsMwZ5o5EmmC1Oan
# &format=zip
wanted_url = base_url + "orthogroups?" + "accession=" + gene_IDs + "&token=" + auth_token + "&format=" + file_format

# Retrieve the wanted orthogroups and if an ok status code is given by the
# server, extract the zipped archive. If a bad status code is given by the
# server, print the attempted URL and the bad status code.
orthogroup_file = requests.get(wanted_url, auth=HTTPDigestAuth("1kp-data", "1kp-rna1"))
if orthogroup_file.status_code == requests.codes.ok:
    #  print 'Success using this URL:', orthogroup_file.url
    orthogroup_file = ZipFile(StringIO(orthogroup_file.content))
    orthogroup_file.extractall()
else:
    orthogroup_file.raise_for_status()
    print "Error using this URL:", orthogroup_file.url
开发者ID:wesleykg,项目名称:orthogroup-workflow,代码行数:32,代码来源:0_download.py


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