1
我試圖下載zip文件中的空間導出。但不知何故python下載一個空的和損壞的zip文件。當你通過瀏覽器下載文件手冊時,一切正常。urllib.urlretrieve下載空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()
我在代碼中看不到任何zipfile;它應該是'f = open(「exportedspaces.txt」,'a')'? – snakecharmerb
@snakecharmerb zipfile由exportSpace API操作生成,該操作可創建可下載的zip文件。例如:Confluence-space-export-122851-90.xml.z –
可能應該將'&'更改爲'&'。 –