I am creating an API where the url is sent to the server. I want to get a username, etc. From URL. For this, I use the following code:
try:
username = request.REQUEST['username']
message = request.REQUEST['message']
time = request.REQUEST['time']
except KeyError:
...
However, there are times when the URL does not contain a username, message, time, etc. In this case, a KeyError occurs. I want to be able to catch this and find out which parameter is missing, so I can issue an error response code that tells the user which parameter is missing. In the exclusion area, is there a way to determine where the code failed to execute?
source
share