我正在使用下面的脚本下载artifactory目录中的所有xml文件(子文件夹名包含各种.xml文件)
from artifactory import ArtifactoryPath
import shutil,os,requests
url="https://artifactory.xxx.com/artifactory/foldername/subfoldername/"
logdirectory='C:\\subfoldername'
if not os.path.exists(logdirectory):
os.mkdir(logdirectory)
os.chdir(logdirectory)
xmlfiles = ArtifactoryPath(url,auth=(username, password))
for element in xmlfiles:
print (element )
xmlname=str(element).split("/")[-1]
print(xmlname)
with requests.get(element , auth=(username, password), stream=True) as r:
with open(xmlname, 'wb') as f:
shutil.copyfileobj(r.raw, f)
它正在下载具有正确名称的xml文件,但当我尝试打开这些文件时,它会显示损坏的数据。
PS:我也尝试了(https://pypi.org/project/artifactory/)上的以下方法,但它也使用我的路径和身份验证代码生成了相同的损坏xml。粘贴在下面的代码供快速参考
from artifactory import ArtifactoryPath
path = ArtifactoryPath(
"http://repo.jfrog.org/artifactory/distributions/org/apache/tomcat/apache-tomcat-7.0.11.tar.gz")
with path.open() as fd:
with open("tomcat.tar.gz", "wb") as out:
out.write(fd.read())
请建议如何下载xml文件而不使其损坏
类似这样的工作原理:
在制品
相关问题 更多 >
编程相关推荐