Format strings have fields inside curly braces. Each field has an optional number, name, or expression, and optional :spec
, and an optional !conversion
.
So, when you use this as a format string:
'{"error":false,"code":"{0}","mac":"{1}","message":"Device configured successfully"}'
You have a field named "error"
, with spec false,"code":"{0}","mac":"{1}","message":"Device configured successfully"
.
To format that field, you need a keyword parameter named "error"
, and of course you don't have one.
Obviously, you didn't want that whole thing to be a field. But that means you need to escape the braces by doubling them:
'{{"error": false,"code":"{0}","mac":"{1}","message":"Device configured successfully"}}'
Or, better… why are you trying to create a JSON string by str.format
in the first place? Why not just create a dict and serialize it?
json_data_resp = json.dumps({
"error": False, "code": activation_code, "mac": macaddress,
"message": "Device configured successfully"})