From b4aa34490d0450917be36388bd249b81ddcd5eb3 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 16 Oct 2019 14:45:51 +0100 Subject: [PATCH] Retry on write --- daemon.py | 730 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 649 insertions(+), 81 deletions(-) diff --git a/daemon.py b/daemon.py index 96a64088..2da9ec8e 100644 --- a/daemon.py +++ b/daemon.py @@ -280,7 +280,15 @@ class PubServer(BaseHTTPRequestHandler): msg='User-agent: *\nDisallow: /' msg=msg.encode('utf-8') self._set_headers('text/plain; charset=utf-8',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return True def _webfinger(self) -> bool: @@ -296,7 +304,15 @@ class PubServer(BaseHTTPRequestHandler): if wfResult: msg=wfResult.encode('utf-8') self._set_headers('application/xrd+xml',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return if self.server.debug: @@ -305,7 +321,15 @@ class PubServer(BaseHTTPRequestHandler): if wfResult: msg=json.dumps(wfResult).encode('utf-8') self._set_headers('application/jrd+json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self.server.debug: print('DEBUG: WEBFINGER lookup 404 '+self.path) @@ -686,7 +710,15 @@ class PubServer(BaseHTTPRequestHandler): optionsLink, \ pageNumber).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return self._redirect_headers(originPathStr,cookie) @@ -703,7 +735,15 @@ class PubServer(BaseHTTPRequestHandler): self.server.GETbusy=False return self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -712,7 +752,15 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.domainFull).encode() self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -721,7 +769,15 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.domainFull).encode() self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -780,8 +836,16 @@ class PubServer(BaseHTTPRequestHandler): tries+=1 msg=css.encode('utf-8') self._set_headers('text/css',len(msg),cookie) - self.wfile.write(msg) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(msg) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return # image on login screen if self.path=='/login.png': @@ -801,8 +865,16 @@ class PubServer(BaseHTTPRequestHandler): tries+=1 if mediaBinary: self._set_headers('image/png',len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -824,8 +896,16 @@ class PubServer(BaseHTTPRequestHandler): tries+=1 if mediaBinary: self._set_headers('image/png',len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -847,8 +927,16 @@ class PubServer(BaseHTTPRequestHandler): tries+=1 if mediaBinary: self._set_headers('image/png',len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -871,8 +959,16 @@ class PubServer(BaseHTTPRequestHandler): with open(emojiFilename, 'rb') as avFile: mediaBinary = avFile.read() self._set_headers('image/'+mediaImageType,len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -908,8 +1004,16 @@ class PubServer(BaseHTTPRequestHandler): with open(mediaFilename, 'rb') as avFile: mediaBinary = avFile.read() self._set_headers(mediaFileType,len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -933,8 +1037,16 @@ class PubServer(BaseHTTPRequestHandler): with open(mediaFilename, 'rb') as avFile: mediaBinary = avFile.read() self._set_headers('image/'+mediaFileType,len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -950,8 +1062,16 @@ class PubServer(BaseHTTPRequestHandler): with open(mediaFilename, 'rb') as avFile: mediaBinary = avFile.read() self._set_headers('image/png',len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -972,8 +1092,16 @@ class PubServer(BaseHTTPRequestHandler): else: self._404() return - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return self._404() return @@ -1002,8 +1130,16 @@ class PubServer(BaseHTTPRequestHandler): with open(avatarFilename, 'rb') as avFile: mediaBinary = avFile.read() self._set_headers('image/'+mediaImageType,len(mediaBinary),cookie) - self.wfile.write(mediaBinary) - self.wfile.flush() + tries=0 + while tries<5: + try: + self.wfile.write(mediaBinary) + self.wfile.flush() + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 return # This busy state helps to avoid flooding @@ -1035,7 +1171,15 @@ class PubServer(BaseHTTPRequestHandler): # request basic auth msg=htmlLogin(self.server.translate,self.server.baseDir).encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -1052,7 +1196,15 @@ class PubServer(BaseHTTPRequestHandler): if isBlockedHashtag(self.server.baseDir,hashtag): msg=htmlHashtagBlocked(self.server.baseDir).encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return hashtagStr= \ @@ -1066,7 +1218,15 @@ class PubServer(BaseHTTPRequestHandler): if hashtagStr: msg=hashtagStr.encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: originPathStr=self.path.split('/tags/')[0] self._redirect_headers(originPathStr+'/search',cookie) @@ -1080,7 +1240,15 @@ class PubServer(BaseHTTPRequestHandler): msg=htmlSearch(self.server.translate, \ self.server.baseDir,self.path).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -1093,7 +1261,15 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.domainFull).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -1105,7 +1281,15 @@ class PubServer(BaseHTTPRequestHandler): self.server.baseDir, \ self.path).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -1379,7 +1563,15 @@ class PubServer(BaseHTTPRequestHandler): self.server.personCache) if deleteStr: self._set_headers('text/html',len(deleteStr),cookie) - self.wfile.write(deleteStr.encode()) + tries=0 + while tries<5: + try: + self.wfile.write(deleteStr.encode()) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return self.server.GETbusy=False @@ -1459,7 +1651,15 @@ class PubServer(BaseHTTPRequestHandler): self.path,self.server.domain, \ self.server.port).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -1478,7 +1678,15 @@ class PubServer(BaseHTTPRequestHandler): shareDescription, \ replyPageNumber).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return @@ -1527,12 +1735,28 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(postJsonObject).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -1588,12 +1812,28 @@ class PubServer(BaseHTTPRequestHandler): self._set_headers('text/html',len(msg),cookie) print('----------------------------------------------------') pprint(repliesJson) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(repliesJson).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -1635,12 +1875,28 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(repliesJson).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -1685,12 +1941,28 @@ class PubServer(BaseHTTPRequestHandler): actorJson['roles'], \ None,None).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(actorJson['roles']).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -1736,12 +2008,28 @@ class PubServer(BaseHTTPRequestHandler): actorJson['skills'], \ None,None).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(actorJson['skills']).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -1798,12 +2086,28 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(postJsonObject).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -1860,13 +2164,29 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: # don't need authenticated fetch here because there is # already the authorization check msg=json.dumps(inboxFeed).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: @@ -1930,13 +2250,29 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: # don't need authenticated fetch here because there is # already the authorization check msg=json.dumps(inboxDMFeed).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: @@ -2003,13 +2339,29 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: # don't need authenticated fetch here because there is # already the authorization check msg=json.dumps(inboxRepliesFeed).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: @@ -2076,13 +2428,29 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: # don't need authenticated fetch here because there is # already the authorization check msg=json.dumps(inboxMediaFeed).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: @@ -2141,12 +2509,28 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(outboxFeed).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -2201,13 +2585,29 @@ class PubServer(BaseHTTPRequestHandler): self.server.httpPrefix, \ self.server.projectVersion).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: # don't need authenticated fetch here because there is # already the authorization check msg=json.dumps(moderationFeed).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: @@ -2263,14 +2663,30 @@ class PubServer(BaseHTTPRequestHandler): shares, \ pageNumber,sharesPerPage).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: if self._fetchAuthenticated(): msg=json.dumps(shares).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -2317,14 +2733,30 @@ class PubServer(BaseHTTPRequestHandler): following, \ pageNumber,followsPerPage).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: if self._fetchAuthenticated(): msg=json.dumps(following).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -2369,14 +2801,30 @@ class PubServer(BaseHTTPRequestHandler): followers, \ pageNumber,followsPerPage).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.GETbusy=False return else: if self._fetchAuthenticated(): msg=json.dumps(followers).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -2403,12 +2851,28 @@ class PubServer(BaseHTTPRequestHandler): self.server.personCache, \ None,None).encode('utf-8') self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self._fetchAuthenticated(): msg=json.dumps(getPerson).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: self._404() self.server.GETbusy=False @@ -2434,7 +2898,15 @@ class PubServer(BaseHTTPRequestHandler): contentJson=json.loads(content) msg=json.dumps(contentJson).encode('utf-8') self._set_headers('application/json',len(msg),None) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 else: if self.server.debug: print('DEBUG: GET Unknown file') @@ -2849,7 +3321,15 @@ class PubServer(BaseHTTPRequestHandler): if isSuspended(self.server.baseDir,loginNickname): msg=htmlSuspended(self.server.baseDir).encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return # login success - redirect with authorization @@ -3166,7 +3646,15 @@ class PubServer(BaseHTTPRequestHandler): msg=htmlModerationInfo(self.server.translate, \ self.server.baseDir).encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return elif moderationStr.startswith('submitBlock'): @@ -3349,7 +3837,15 @@ class PubServer(BaseHTTPRequestHandler): if hashtagStr: msg=hashtagStr.encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return elif searchStr.startswith('*'): @@ -3363,7 +3859,15 @@ class PubServer(BaseHTTPRequestHandler): if skillStr: msg=skillStr.encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return elif '@' in searchStr: @@ -3390,7 +3894,15 @@ class PubServer(BaseHTTPRequestHandler): if profileStr: msg=profileStr.encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return else: @@ -3408,7 +3920,15 @@ class PubServer(BaseHTTPRequestHandler): if emojiStr: msg=emojiStr.encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return else: @@ -3424,7 +3944,15 @@ class PubServer(BaseHTTPRequestHandler): if sharedItemsStr: msg=sharedItemsStr.encode('utf-8') self._login_headers('text/html',len(msg)) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return self._redirect_headers(actorStr+'/inbox',cookie) @@ -3728,7 +4256,15 @@ class PubServer(BaseHTTPRequestHandler): optionsActor, \ optionsAvatarUrl).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return if '&submitFollow=' in optionsConfirmParams: @@ -3740,7 +4276,15 @@ class PubServer(BaseHTTPRequestHandler): optionsActor, \ optionsAvatarUrl).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return if '&submitUnfollow=' in optionsConfirmParams: @@ -3752,7 +4296,15 @@ class PubServer(BaseHTTPRequestHandler): optionsActor, \ optionsAvatarUrl).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return if '&submitDM=' in optionsConfirmParams: @@ -3765,7 +4317,15 @@ class PubServer(BaseHTTPRequestHandler): [optionsActor],None, \ pageNumber).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return if '&submitReport=' in optionsConfirmParams: @@ -3777,7 +4337,15 @@ class PubServer(BaseHTTPRequestHandler): reportPath,None,[], \ postUrl,pageNumber).encode() self._set_headers('text/html',len(msg),cookie) - self.wfile.write(msg) + tries=0 + while tries<5: + try: + self.wfile.write(msg) + break + except Exception as e: + print(e) + time.sleep(1) + tries+=1 self.server.POSTbusy=False return