【发布时间】:2018-05-12 08:47:21
【问题描述】:
我正在 OSX 上运行一个 python 脚本来将视频文件 (single_file) 上传到 YouTube:
# define recording date as date of file modification
# https://developers.google.com/youtube/v3/docs/videos#resource
recordingDate = datetime.fromtimestamp(os.path.getctime(single_file)).isoformat("T")+"Z"
# define video title as file name
filename, file_extension = os.path.splitext(os.path.basename(single_file))
try:
initialize_upload(youtube, args, single_file, title, recordingDate)
except HttpError, e:
print " An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)
在某些情况下它运行良好,但在其他情况下,Google 会返回以下错误 -
Invalid value for: Invalid format: \"2017-09-22T22:50:55Z\" is malformed at \"Z\"
我应该如何修复它以从文件中获取正确的日期? YouTube 需要 ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) 格式的值。
【问题讨论】:
-
有效的日期是什么时候?
-
看起来他们也可能需要 1/10 秒。你有没有试过
+".0Z"而不是+"Z"?
标签: python datetime youtube-api datetime-format