2016-01-21 43 views
1

需要使用Artifactory REST API從Artifactory下載artefact。請求GET不完全保存文件

我的代碼是:

with open(jfrog_testfile, 'wb') as outfile: 
    data = requests.get(baseurl, auth=(jfrog_user, jfrog_pswd), stream=True) 
    shutil.copyfileobj(data.raw, outfile) 
    data.raise_for_status() 

而另一次嘗試用相同的結果:

with open(jfrog_testfile, 'wb') as outfile: 
    data = requests.get(baseurl, auth=(jfrog_user, jfrog_pswd), stream=True) 
    for chunk in data.iter_content(65536): 
     outfile.write(chunk) 
    data.raise_for_status() 

baseurl是正確的,即:

baseurl = os.path.join(jfrog_url, jfrog_api, jfrog_repo, jfrog_tetstdir, jfrog_testfile) 

print(baseurl) 

回報:

https://project.artifactoryonline.com/project/api/storage/project-releases-local/ppp/artefact.war 

問題是 - 這正是假象大小爲5.7 MB,但reqeust後 - 我只拿到了841個字節:

$ ls -l artefact.war 
-rw-r--r-- 1 username staff 841 Jan 21 11:47 artefact.war 

即使我跑同樣的要求與curl -o - 我有相同的841個字節。 使用wget - 我有整個文件,5,7 MB。 (e)y請求有什麼不對?

回答

1

我的錯誤出現在GET的URL中。

URL由來自:

jfrog_url = 'https://project.artifactoryonline.com/project/' 
jfrog_api = 'api/storage/' 
jfrog_repo = 'project-releases-local' 
jfrog_tetstdir = 'artefact' 
jfrog_testfile = 'artefact.war' 

和:

baseurl = os.path.join(jfrog_url, jfrog_repo, jfrog_tetstdir, jfrog_testfile)

對於GET不需要請求插入jfrog_api

代替,:

requests.get('https://project.artifactoryonline.com/project/api/storage/project-releases-local/ppp/artefact.war')

必須使用:

requests.get(https://project.artifactoryonline.com/project/project-releases-local/ppp/artefact.war')

'api/storage/'將需要爲PUT/POST請求,我記得。