python - urllib.urlretrieve 下载空的 zip 文件

标签 python python-2.7 urllib confluence confluence-rest-api

我正在尝试下载 zip 文件中的空间导出。但不知何故,python 下载了一个空且损坏的 zip 文件。当您通过浏览器下载文件手册时一切正常。

我使用Python 2.7.13

#!/usr/bin/python
import xmlrpclib
import time
import urllib

confluencesite = "https://confluence.com"
server = xmlrpclib.ServerProxy(confluencesite + '/rpc/xmlrpc')
username = '*'
password = '*'
token = server.confluence2.login(username, password)
loginString = "?os_username=" + username + "&os_password=" + password
filelist = ""
start = True
spacesummary = server.confluence2.getSpaces(token)
for space in spacesummary:
    #if space['name'] == "24-codING":
    #    start = True
    #    continue
    if start:
        if space['type'] == 'global':
            print "Exporting space " + space['name']
            spaceDownloadUrl = server.confluence2.exportSpace(token, space['key'],
                                                              "TYPE_XML",
                                                              exportAll['true'])
            filename = spaceDownloadUrl.split('/')[-1].split('#')[0].split('?')[0]
            time.sleep(0.5)
            urllib.urlretrieve(spaceDownloadUrl + loginString, filename)
            print filename + " saved."
            f = open("exportedspaces.txt", 'a')
            f.write(filename + "\n")
            f.close()

最佳答案

按照Coldspeed的回答已经解决了。更改以下内容:

loginString = "?os_username=" + username + "&os_password=" + password
to
loginString = "?os_username=" + username + "&os_password=" + password

关于python - urllib.urlretrieve 下载空的 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44630823/

相关文章:

python - 通过单元测试避免不必要的导入

Python 请求 URLLib3 连接池大小

python - 如何创建 pandas "link"(href) 样式?

python - python中的重复导入路径模式

python - 如何从字典列表中获取字典

Python:搜索带有 href 和文本内容的 html 文件抓取 <a> 标签

python - urllib.urlretrieve 编码不保留

python - 在纸牌游戏中拆分和附加列表

python - 使用类型在 python 中动态创建类 - 为什么创建的类对象不相同?

python - 如何在Python中返回url路径的子字符串?