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