I'm using Python 3.9 and using http.client to authenticate and generate a token. When I send the request, I get this response:
{"token":"eyJhbGciOiJ","user":{"id":99,"username":"[email protected]","tenantUuid":"-888-888-52558-878745"}
How can I extract the token part and store it in a variable that I can use later on?
CodePudding user response:
Assuming data
holds the dictionary, you could do:
token = data["token"]
CodePudding user response:
For consistency, if the token is missing you should use a get statement to avoid a potential exception. get
accepts a default value if no 'token' key is found.
data = myRequestFn(inputs, here)
token = data.get('token','default_variable_here')