Can't pass DateTime with timezone to marshmallow

1.9k views Asked by At

I need to pass a DateTime with timezone to a Flask api, using marshmallow/webargs arguments definitions. I have my argument defined as:

from webargs import fields
'from': fields.DateTime(required=False, missing=None)

I am calling my api passing the argument as:

from=2018-03-03T00:00:00.000000+00:50

but I obtain this error:

'from': ['Not a valid datetime.']

where I'm wrong?

1

There are 1 answers

0
Felix On

I encountered the same issue. The "+" is coming in as " " (a space) after decoding the url, because the query string has not been url encoded. To get around this, you can url encode your query string to get:

from=2018-03-03T00%3A00%3A00.000000%2B00%3A50

or directly use "%2B" instead of "+" to get:

from=2018-03-03T00:00:00.000000%2B00:50