mirror of https://gitlab.com/bashrc2/epicyon
Timeout on post
parent
63b7aa6d94
commit
d6efc44fe2
|
@ -256,7 +256,8 @@ def sendAnnounceViaServer(baseDir: str, session,
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = postJson(session, newAnnounceJson, [], inboxUrl, headers)
|
postResult = postJson(session, newAnnounceJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
print('WARN: Announce not posted')
|
print('WARN: Announce not posted')
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ def sendAvailabilityViaServer(baseDir: str, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = postJson(session, newAvailabilityJson, [],
|
postResult = postJson(session, newAvailabilityJson, [],
|
||||||
inboxUrl, headers)
|
inboxUrl, headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
print('WARN: failed to post availability')
|
print('WARN: failed to post availability')
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ def sendDeleteViaServer(baseDir: str, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, newDeleteJson, [], inboxUrl, headers)
|
postJson(session, newDeleteJson, [], inboxUrl, headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||||
|
|
|
@ -1004,7 +1004,7 @@ def sendFollowRequestViaServer(baseDir: str, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, newFollowJson, [], inboxUrl, headers)
|
postJson(session, newFollowJson, [], inboxUrl, headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||||
|
@ -1096,7 +1096,7 @@ def sendUnfollowRequestViaServer(baseDir: str, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, unfollowJson, [], inboxUrl, headers)
|
postJson(session, unfollowJson, [], inboxUrl, headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||||
|
|
6
like.py
6
like.py
|
@ -203,7 +203,8 @@ def sendLikeViaServer(baseDir: str, session,
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = postJson(session, newLikeJson, [], inboxUrl, headers, 30)
|
postResult = postJson(session, newLikeJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
print('WARN: POST announce failed for c2s to ' + inboxUrl)
|
print('WARN: POST announce failed for c2s to ' + inboxUrl)
|
||||||
return 5
|
return 5
|
||||||
|
@ -282,7 +283,8 @@ def sendUndoLikeViaServer(baseDir: str, session,
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = postJson(session, newUndoLikeJson, [], inboxUrl, headers)
|
postResult = postJson(session, newUndoLikeJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
print('WARN: POST announce failed for c2s to ' + inboxUrl)
|
print('WARN: POST announce failed for c2s to ' + inboxUrl)
|
||||||
return 5
|
return 5
|
||||||
|
|
8
posts.py
8
posts.py
|
@ -2141,7 +2141,7 @@ def sendPostViaServer(projectVersion: str,
|
||||||
postDumps = json.dumps(postJsonObject)
|
postDumps = json.dumps(postJsonObject)
|
||||||
postResult = \
|
postResult = \
|
||||||
postJsonString(session, postDumps, [],
|
postJsonString(session, postDumps, [],
|
||||||
inboxUrl, headers, debug, 60)
|
inboxUrl, headers, debug, 60, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST failed for c2s to '+inboxUrl)
|
print('DEBUG: POST failed for c2s to '+inboxUrl)
|
||||||
|
@ -4184,7 +4184,8 @@ def sendBlockViaServer(baseDir: str, session,
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = postJson(session, newBlockJson, [], inboxUrl, headers)
|
postResult = postJson(session, newBlockJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
print('WARN: Unable to post block')
|
print('WARN: Unable to post block')
|
||||||
|
|
||||||
|
@ -4266,7 +4267,8 @@ def sendUndoBlockViaServer(baseDir: str, session,
|
||||||
'Content-type': 'application/json',
|
'Content-type': 'application/json',
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = postJson(session, newBlockJson, [], inboxUrl, headers)
|
postResult = postJson(session, newBlockJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
print('WARN: Unable to post block')
|
print('WARN: Unable to post block')
|
||||||
|
|
||||||
|
|
2
roles.py
2
roles.py
|
@ -349,7 +349,7 @@ def sendRoleViaServer(baseDir: str, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, newRoleJson, [], inboxUrl, headers)
|
postJson(session, newRoleJson, [], inboxUrl, headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to '+inboxUrl)
|
print('DEBUG: POST announce failed for c2s to '+inboxUrl)
|
||||||
|
|
54
session.py
54
session.py
|
@ -137,12 +137,13 @@ def getJson(session, url: str, headers: {}, params: {},
|
||||||
|
|
||||||
|
|
||||||
def postJson(session, postJsonObject: {}, federationList: [],
|
def postJson(session, postJsonObject: {}, federationList: [],
|
||||||
inboxUrl: str, headers: {}, timeoutSec=60) -> str:
|
inboxUrl: str, headers: {}, timeoutSec=60, quiet=False) -> str:
|
||||||
"""Post a json message to the inbox of another person
|
"""Post a json message to the inbox of another person
|
||||||
"""
|
"""
|
||||||
# check that we are posting to a permitted domain
|
# check that we are posting to a permitted domain
|
||||||
if not urlPermitted(inboxUrl, federationList):
|
if not urlPermitted(inboxUrl, federationList):
|
||||||
print('postJson: ' + inboxUrl + ' not permitted')
|
if not quiet:
|
||||||
|
print('postJson: ' + inboxUrl + ' not permitted')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -151,18 +152,20 @@ def postJson(session, postJsonObject: {}, federationList: [],
|
||||||
data=json.dumps(postJsonObject),
|
data=json.dumps(postJsonObject),
|
||||||
headers=headers, timeout=timeoutSec)
|
headers=headers, timeout=timeoutSec)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print('ERROR: postJson requests failed ' + inboxUrl + ' ' +
|
if not quiet:
|
||||||
json.dumps(postJsonObject) + ' ' + str(headers))
|
print('ERROR: postJson requests failed ' + inboxUrl + ' ' +
|
||||||
print(e)
|
json.dumps(postJsonObject) + ' ' + str(headers))
|
||||||
|
print(e)
|
||||||
return None
|
return None
|
||||||
except SocketError as e:
|
except SocketError as e:
|
||||||
if e.errno == errno.ECONNRESET:
|
if not quiet and e.errno == errno.ECONNRESET:
|
||||||
print('WARN: connection was reset during postJson')
|
print('WARN: connection was reset during postJson')
|
||||||
return None
|
return None
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print('ERROR: postJson failed ' + inboxUrl + ' ' +
|
if not quiet:
|
||||||
json.dumps(postJsonObject) + ' ' + str(headers))
|
print('ERROR: postJson failed ' + inboxUrl + ' ' +
|
||||||
print(e)
|
json.dumps(postJsonObject) + ' ' + str(headers))
|
||||||
|
print(e)
|
||||||
return None
|
return None
|
||||||
if postResult:
|
if postResult:
|
||||||
return postResult.text
|
return postResult.text
|
||||||
|
@ -174,7 +177,8 @@ def postJsonString(session, postJsonStr: str,
|
||||||
inboxUrl: str,
|
inboxUrl: str,
|
||||||
headers: {},
|
headers: {},
|
||||||
debug: bool,
|
debug: bool,
|
||||||
timeoutSec=30) -> (bool, bool):
|
timeoutSec=30,
|
||||||
|
quiet=False) -> (bool, bool):
|
||||||
"""Post a json message string to the inbox of another person
|
"""Post a json message string to the inbox of another person
|
||||||
The second boolean returned is true if the send is unauthorized
|
The second boolean returned is true if the send is unauthorized
|
||||||
NOTE: Here we post a string rather than the original json so that
|
NOTE: Here we post a string rather than the original json so that
|
||||||
|
@ -186,30 +190,36 @@ def postJsonString(session, postJsonStr: str,
|
||||||
session.post(url=inboxUrl, data=postJsonStr,
|
session.post(url=inboxUrl, data=postJsonStr,
|
||||||
headers=headers, timeout=timeoutSec)
|
headers=headers, timeout=timeoutSec)
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
print('WARN: error during postJsonString requests')
|
if not quiet:
|
||||||
print(e)
|
print('WARN: error during postJsonString requests')
|
||||||
|
print(e)
|
||||||
return None, None
|
return None, None
|
||||||
except SocketError as e:
|
except SocketError as e:
|
||||||
if e.errno == errno.ECONNRESET:
|
if not quiet and e.errno == errno.ECONNRESET:
|
||||||
print('WARN: connection was reset during postJsonString')
|
print('WARN: connection was reset during postJsonString')
|
||||||
print('ERROR: postJsonString failed ' + inboxUrl + ' ' +
|
if not quiet:
|
||||||
postJsonStr + ' ' + str(headers))
|
print('ERROR: postJsonString failed ' + inboxUrl + ' ' +
|
||||||
|
postJsonStr + ' ' + str(headers))
|
||||||
return None, None
|
return None, None
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
print('WARN: error during postJsonString')
|
if not quiet:
|
||||||
print(e)
|
print('WARN: error during postJsonString')
|
||||||
|
print(e)
|
||||||
return None, None
|
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 \
|
||||||
postResult.status_code != 404:
|
postResult.status_code != 404:
|
||||||
print('WARN: Post to ' + inboxUrl + ' is unauthorized. Code ' +
|
if not quiet:
|
||||||
str(postResult.status_code))
|
print('WARN: Post to ' + inboxUrl +
|
||||||
|
' is unauthorized. Code ' +
|
||||||
|
str(postResult.status_code))
|
||||||
return False, True
|
return False, True
|
||||||
else:
|
else:
|
||||||
print('WARN: Failed to post to ' + inboxUrl +
|
if not quiet:
|
||||||
' with headers ' + str(headers))
|
print('WARN: Failed to post to ' + inboxUrl +
|
||||||
print('status code ' + str(postResult.status_code))
|
' with headers ' + str(headers))
|
||||||
|
print('status code ' + str(postResult.status_code))
|
||||||
return False, False
|
return False, False
|
||||||
return True, False
|
return True, False
|
||||||
|
|
||||||
|
|
|
@ -406,7 +406,7 @@ def sendShareViaServer(baseDir, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, newShareJson, [], inboxUrl, headers)
|
postJson(session, newShareJson, [], inboxUrl, headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||||
|
@ -495,7 +495,8 @@ def sendUndoShareViaServer(baseDir: str, session,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, undoShareJson, [], inboxUrl, headers)
|
postJson(session, undoShareJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||||
|
|
|
@ -160,7 +160,8 @@ def sendSkillViaServer(baseDir: str, session, nickname: str, password: str,
|
||||||
'Authorization': authHeader
|
'Authorization': authHeader
|
||||||
}
|
}
|
||||||
postResult = \
|
postResult = \
|
||||||
postJson(session, newSkillJson, [], inboxUrl, headers)
|
postJson(session, newSkillJson, [], inboxUrl,
|
||||||
|
headers, 30, True)
|
||||||
if not postResult:
|
if not postResult:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
print('DEBUG: POST announce failed for c2s to ' + inboxUrl)
|
||||||
|
|
Loading…
Reference in New Issue