mirror of https://gitlab.com/bashrc2/epicyon
Session error handling
parent
48f0f81a9f
commit
4fecd1fa3a
22
session.py
22
session.py
|
@ -51,10 +51,9 @@ def getJson(session, url: str, headers: {}, params: {},
|
||||||
result = session.get(url, headers=sessionHeaders, params=sessionParams)
|
result = session.get(url, headers=sessionHeaders, params=sessionParams)
|
||||||
return result.json()
|
return result.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('ERROR: getJson failed')
|
print('ERROR: getJson failed\nurl: ' + str(url) + '\n' +
|
||||||
print('url: ' + str(url))
|
'headers: ' + str(sessionHeaders) + '\n' +
|
||||||
print('headers: ' + str(sessionHeaders))
|
'params: ' + str(sessionParams))
|
||||||
print('params: ' + str(sessionParams))
|
|
||||||
print(e)
|
print(e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -71,10 +70,15 @@ def postJson(session, postJsonObject: {}, federationList: [],
|
||||||
print('postJson: ' + inboxUrl + ' not permitted')
|
print('postJson: ' + inboxUrl + ' not permitted')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
postResult = \
|
postResult = \
|
||||||
session.post(url=inboxUrl,
|
session.post(url=inboxUrl,
|
||||||
data=json.dumps(postJsonObject),
|
data=json.dumps(postJsonObject),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
|
except BaseException:
|
||||||
|
print('ERROR: postJson failed ' + inboxUrl + ' ' +
|
||||||
|
json.dumps(postJsonObject) + ' ' + str(headers))
|
||||||
|
return None
|
||||||
if postResult:
|
if postResult:
|
||||||
return postResult.text
|
return postResult.text
|
||||||
return None
|
return None
|
||||||
|
@ -100,8 +104,13 @@ def postJsonString(session, postJsonStr: str,
|
||||||
print('postJson: ' + inboxUrl + ' not permitted by capabilities')
|
print('postJson: ' + inboxUrl + ' not permitted by capabilities')
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
try:
|
||||||
postResult = \
|
postResult = \
|
||||||
session.post(url=inboxUrl, data=postJsonStr, headers=headers)
|
session.post(url=inboxUrl, data=postJsonStr, headers=headers)
|
||||||
|
except BaseException:
|
||||||
|
print('ERROR: postJsonString failed ' + inboxUrl + ' ' +
|
||||||
|
postJsonStr + ' ' + str(headers))
|
||||||
|
return None, None
|
||||||
if postResult.status_code < 200 or postResult.status_code > 202:
|
if postResult.status_code < 200 or postResult.status_code > 202:
|
||||||
if postResult.status_code >= 400 and \
|
if postResult.status_code >= 400 and \
|
||||||
postResult.status_code <= 405 and \
|
postResult.status_code <= 405 and \
|
||||||
|
@ -148,8 +157,13 @@ def postImage(session, attachImageFilename: str, federationList: [],
|
||||||
|
|
||||||
with open(attachImageFilename, 'rb') as avFile:
|
with open(attachImageFilename, 'rb') as avFile:
|
||||||
mediaBinary = avFile.read()
|
mediaBinary = avFile.read()
|
||||||
|
try:
|
||||||
postResult = session.post(url=inboxUrl, data=mediaBinary,
|
postResult = session.post(url=inboxUrl, data=mediaBinary,
|
||||||
headers=headers)
|
headers=headers)
|
||||||
|
except BaseException:
|
||||||
|
print('ERROR: postImage failed ' + inboxUrl + ' ' +
|
||||||
|
str(headers))
|
||||||
|
return None
|
||||||
if postResult:
|
if postResult:
|
||||||
return postResult.text
|
return postResult.text
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue