mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 14:44:21 +01:00
Fixes json parsing of None when no json was postesd to the API
h/t @yahgwai for finding this.
This commit is contained in:
@@ -36,7 +36,7 @@ This command is used to register appointments to the PISA server. Appointments *
|
|||||||
"tx_id": tx_id,
|
"tx_id": tx_id,
|
||||||
"start_time": s,
|
"start_time": s,
|
||||||
"end_time": e,
|
"end_time": e,
|
||||||
"dispute_delta": d }
|
"to_self_delay": d }
|
||||||
|
|
||||||
`tx` **must** be the raw penalty transaction that will be encrypted before sent to the PISA server. `type(tx) = hex encoded str`
|
`tx` **must** be the raw penalty transaction that will be encrypted before sent to the PISA server. `type(tx) = hex encoded str`
|
||||||
|
|
||||||
|
|||||||
48
pisa/api.py
48
pisa/api.py
@@ -40,35 +40,41 @@ class API:
|
|||||||
|
|
||||||
logger.info("Received add_appointment request", from_addr_port="{}:{}".format(remote_addr, remote_port))
|
logger.info("Received add_appointment request", from_addr_port="{}:{}".format(remote_addr, remote_port))
|
||||||
|
|
||||||
# Check content type once if properly defined
|
if request.is_json:
|
||||||
request_data = json.loads(request.get_json())
|
# Check content type once if properly defined
|
||||||
inspector = Inspector(self.config)
|
request_data = json.loads(request.get_json())
|
||||||
appointment = inspector.inspect(
|
inspector = Inspector(self.config)
|
||||||
request_data.get("appointment"), request_data.get("signature"), request_data.get("public_key")
|
appointment = inspector.inspect(
|
||||||
)
|
request_data.get("appointment"), request_data.get("signature"), request_data.get("public_key")
|
||||||
|
)
|
||||||
|
|
||||||
error = None
|
error = None
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
if type(appointment) == Appointment:
|
if type(appointment) == Appointment:
|
||||||
appointment_added, signature = self.watcher.add_appointment(appointment)
|
appointment_added, signature = self.watcher.add_appointment(appointment)
|
||||||
|
|
||||||
if appointment_added:
|
if appointment_added:
|
||||||
rcode = HTTP_OK
|
rcode = HTTP_OK
|
||||||
response = {"locator": appointment.locator, "signature": signature}
|
response = {"locator": appointment.locator, "signature": signature}
|
||||||
|
|
||||||
|
else:
|
||||||
|
rcode = HTTP_SERVICE_UNAVAILABLE
|
||||||
|
error = "appointment rejected"
|
||||||
|
|
||||||
|
elif type(appointment) == tuple:
|
||||||
|
rcode = HTTP_BAD_REQUEST
|
||||||
|
error = "appointment rejected. Error {}: {}".format(appointment[0], appointment[1])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
rcode = HTTP_SERVICE_UNAVAILABLE
|
# We should never end up here, since inspect only returns appointments or tuples. Just in case.
|
||||||
error = "appointment rejected"
|
rcode = HTTP_BAD_REQUEST
|
||||||
|
error = "appointment rejected. Request does not match the standard"
|
||||||
elif type(appointment) == tuple:
|
|
||||||
rcode = HTTP_BAD_REQUEST
|
|
||||||
error = "appointment rejected. Error {}: {}".format(appointment[0], appointment[1])
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# We should never end up here, since inspect only returns appointments or tuples. Just in case.
|
|
||||||
rcode = HTTP_BAD_REQUEST
|
rcode = HTTP_BAD_REQUEST
|
||||||
error = "appointment rejected. Request does not match the standard"
|
error = "appointment rejected. Request is not json encoded"
|
||||||
|
response = None
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"Sending response and disconnecting",
|
"Sending response and disconnecting",
|
||||||
|
|||||||
Reference in New Issue
Block a user