Check status code

main2
Bob Mottram 2019-09-14 20:39:51 +01:00
parent a99eb91544
commit 78fcf1618f
1 changed files with 10 additions and 7 deletions

View File

@ -64,6 +64,12 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata
try:
print('avatar image url: '+avatarUrl)
result=session.get(avatarUrl, headers=sessionHeaders, params=None)
if result.status_code<200 or result.status_code>202:
print('Avatar image download failed with status '+str(result.status_code))
# remove partial download
if os.path.isfile(avatarImageFilename):
os.remove(avatarImageFilename)
else:
with open(avatarImageFilename, 'wb') as f:
f.write(result.content)
print('avatar image downloaded for '+actor)
@ -71,9 +77,6 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata
except Exception as e:
print('Failed to download avatar image: '+str(avatarUrl))
print(e)
# remove partial download
if os.path.isfile(avatarImageFilename):
os.remove(avatarImageFilename)
sessionHeaders = {'Accept': 'application/activity+json; profile="https://www.w3.org/ns/activitystreams"'}
personJson = getJson(session,actor,sessionHeaders,None,__version__,httpPrefix,None)
if personJson: