2
Hello. I am writing a schema and need to understand how to make a list using the Python Eve and Cerberus. Currently I write how the documentation teaches me:
'datasources': {'type': 'list', 'schema':{'type':'string'}}
But when I try to send a POST with a list for this parameter I keep getting
"datasources": "must be of list type"
.
I have tried sending in the following ways:
'teste1,teste2'
,
[teste1,teste2]
,
['teste1','teste2'],
'[teste1,teste2]'
. But none of these are accepted. Not even using the example given in the Cerberus link can I send a list. Any idea why? Thanks
The correct way is: ['valor1', 'valor2']. What you should look at is whether what you’re really trying to validate is actually a list, or a string that represents a list. If you are receiving a value through POST, it will probably not be a list, but a string. In that case, you’ll have to convert to the list. To confirm my hypothesis, take the "list"that you are receiving via POST, and test by the following command:
print(type(lista))
. The correct value of this output to function properly should be<type 'list'>
– Marcelo Theodoro