Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

amazon web services - Is this valid ISO8601 string?

2012-12-11T00:00:00+00:00

One of the AWS service returned error for this

ErrorMessage    Attribute submission-date is an invalid ISO 8601 String

Code I used to convert epoch time to ISO 8601 is below:

datetime.fromtimestamp(<epochTimeHere>, timezone.utc).isoformat()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, a format like 2012-12-11T00:00:00+00:00 is specified by ISO 8601 - see e.g. wikipedia/ISO8601 or C.4.2 Date and Time of ISO/TC154N, p.29.

From the comment section, it seems however that the AWS service (Kendra) expects a Z for UTC (see also Kendra docs) , instead of +00:00 as returned by the Python code. A simple work-around can be a string-replace:

datetime.fromtimestamp(<epochTimeHere>, timezone.utc).isoformat().replace('+00:00', 'Z')

Side note - Python offers a catch in the other direction as well, i.e. when parsing ISO 8601 timestamps: the built-in datetime.fromisoformat method won't parse Z to UTC, but only +00:00.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...