forked from indymedia/epicyon
More exception handling
parent
306af20d45
commit
b7653b9eb1
4
posts.py
4
posts.py
|
@ -6,7 +6,6 @@ __maintainer__ = "Bob Mottram"
|
|||
__email__ = "bob@freedombone.net"
|
||||
__status__ = "Production"
|
||||
|
||||
import random
|
||||
import json
|
||||
import html
|
||||
import datetime
|
||||
|
@ -14,6 +13,7 @@ import os
|
|||
import shutil
|
||||
import sys
|
||||
import time
|
||||
from socket import error as SocketError
|
||||
from time import gmtime, strftime
|
||||
from collections import OrderedDict
|
||||
from threads import threadWithTrace
|
||||
|
@ -2173,7 +2173,7 @@ def sendToFollowersThread(session, baseDir: str,
|
|||
print('WARN: socket error while starting ' +
|
||||
'thread to send to followers. ' + str(e))
|
||||
return None
|
||||
except BaseException:
|
||||
except ValueError as e:
|
||||
print('WARN: error while starting ' +
|
||||
'thread to send to followers. ' + str(e))
|
||||
return None
|
||||
|
|
38
session.py
38
session.py
|
@ -20,8 +20,8 @@ def createSession(proxyType: str):
|
|||
session = None
|
||||
try:
|
||||
session = requests.session()
|
||||
except ValueError as e:
|
||||
print('WARN: error during createSession')
|
||||
except requests.exceptions.RequestException as e:
|
||||
print('WARN: requests error during createSession')
|
||||
print(e)
|
||||
return None
|
||||
except SocketError as e:
|
||||
|
@ -31,6 +31,10 @@ def createSession(proxyType: str):
|
|||
print('WARN: socket error during createSession')
|
||||
print(e)
|
||||
return None
|
||||
except ValueError as e:
|
||||
print('WARN: error during createSession')
|
||||
print(e)
|
||||
return None
|
||||
if not session:
|
||||
return None
|
||||
if proxyType == 'tor':
|
||||
|
@ -70,6 +74,11 @@ def getJson(session, url: str, headers: {}, params: {},
|
|||
try:
|
||||
result = session.get(url, headers=sessionHeaders, params=sessionParams)
|
||||
return result.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print('ERROR: getJson failed\nurl: ' + str(url) + '\n' +
|
||||
'headers: ' + str(sessionHeaders) + '\n' +
|
||||
'params: ' + str(sessionParams) + '\n')
|
||||
print(e)
|
||||
except ValueError as e:
|
||||
print('ERROR: getJson failed\nurl: ' + str(url) + '\n' +
|
||||
'headers: ' + str(sessionHeaders) + '\n' +
|
||||
|
@ -99,8 +108,8 @@ def postJson(session, postJsonObject: {}, federationList: [],
|
|||
session.post(url=inboxUrl,
|
||||
data=json.dumps(postJsonObject),
|
||||
headers=headers)
|
||||
except ValueError as e:
|
||||
print('ERROR: postJson failed ' + inboxUrl + ' ' +
|
||||
except requests.exceptions.RequestException as e:
|
||||
print('ERROR: postJson requests failed ' + inboxUrl + ' ' +
|
||||
json.dumps(postJsonObject) + ' ' + str(headers))
|
||||
print(e)
|
||||
return None
|
||||
|
@ -108,6 +117,11 @@ def postJson(session, postJsonObject: {}, federationList: [],
|
|||
if e.errno == errno.ECONNRESET:
|
||||
print('WARN: connection was reset during postJson')
|
||||
return None
|
||||
except ValueError as e:
|
||||
print('ERROR: postJson failed ' + inboxUrl + ' ' +
|
||||
json.dumps(postJsonObject) + ' ' + str(headers))
|
||||
print(e)
|
||||
return None
|
||||
if postResult:
|
||||
return postResult.text
|
||||
return None
|
||||
|
@ -136,8 +150,8 @@ def postJsonString(session, postJsonStr: str,
|
|||
try:
|
||||
postResult = \
|
||||
session.post(url=inboxUrl, data=postJsonStr, headers=headers)
|
||||
except ValueError as e:
|
||||
print('WARN: error during postJsonString')
|
||||
except requests.exceptions.RequestException as e:
|
||||
print('WARN: error during postJsonString requests')
|
||||
print(e)
|
||||
return None, None
|
||||
except SocketError as e:
|
||||
|
@ -146,6 +160,10 @@ def postJsonString(session, postJsonStr: str,
|
|||
print('ERROR: postJsonString failed ' + inboxUrl + ' ' +
|
||||
postJsonStr + ' ' + str(headers))
|
||||
return None, None
|
||||
except ValueError as e:
|
||||
print('WARN: error during postJsonString')
|
||||
print(e)
|
||||
return None, None
|
||||
if postResult.status_code < 200 or postResult.status_code > 202:
|
||||
if postResult.status_code >= 400 and \
|
||||
postResult.status_code <= 405 and \
|
||||
|
@ -195,8 +213,8 @@ def postImage(session, attachImageFilename: str, federationList: [],
|
|||
try:
|
||||
postResult = session.post(url=inboxUrl, data=mediaBinary,
|
||||
headers=headers)
|
||||
except ValueError as e:
|
||||
print('WARN: error during postImage')
|
||||
except requests.exceptions.RequestException as e:
|
||||
print('WARN: error during postImage requests')
|
||||
print(e)
|
||||
return None
|
||||
except SocketError as e:
|
||||
|
@ -206,6 +224,10 @@ def postImage(session, attachImageFilename: str, federationList: [],
|
|||
str(headers))
|
||||
print(e)
|
||||
return None
|
||||
except ValueError as e:
|
||||
print('WARN: error during postImage')
|
||||
print(e)
|
||||
return None
|
||||
if postResult:
|
||||
return postResult.text
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue