diff --git a/webinterface.py b/webinterface.py index 96df86730..2dfb8e64f 100644 --- a/webinterface.py +++ b/webinterface.py @@ -64,16 +64,19 @@ def updateAvatarImageCache(session,baseDir: str,httpPrefix: str,actor: str,avata try: print('avatar image url: '+avatarUrl) result=session.get(avatarUrl, headers=sessionHeaders, params=None) - with open(avatarImageFilename, 'wb') as f: - f.write(result.content) - print('avatar image downloaded for '+actor) - return avatarImageFilename.replace(baseDir+'/cache','') + 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) + return avatarImageFilename.replace(baseDir+'/cache','') 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: