【发布时间】:2014-07-22 12:29:41
【问题描述】:
我正在使用 GCS 客户端库在我的 App Engine 应用中使用 Python 将文件写入 Google Cloud Storage。
在创建文件之前,我需要确保它不存在以避免覆盖。
为此,我在尝试创建文件之前检查文件是否存在:
import cloudstorage as gcs
try:
gcs_file = gcs.open(filename, 'r')
gcs_file.close()
return "File Exists!"
except gcs.NotFoundError as e:
return "File Does Not Exist: " + str(e)
cloudstorage.write() 正在记录(直接或间接)它在尝试读取不存在的文件时收到 404 错误的事实。如果可能的话,我想压制它。
谢谢
编辑 以下是记录的内容:
12:19:32.565 暂停生成器_get_segment(storage_api.py:432) 从 Google 存储中引发 NotFoundError(期望状态 [200, 206]。但是 得到状态 404。路径: '/cs-mailing/bde24e63-4d31-41e5-8aff-14b76b239388.html'。要求 标头:{'范围':'bytes = 0-1048575','x-goog-api-version':'2', '接受编码':'gzip,*'}。响应标头: {'alternate-protocol': '443:quic', 'content-length': '127', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': 'remote-fetch', 'expires': '星期一,2014 年 6 月 2 日 11:19:32 GMT','服务器':'HTTP 上传服务器已构建 在 2014 年 5 月 19 日 09:31:01 (1400517061)','缓存控制':'私人, max-age=0', 'date': 'Mon, 02 Jun 2014 11:19:32 GMT', 'content-type': '应用程序/xml;字符集=UTF-8'}。正文:“
NoSuchKey指定的 密钥不存在。”。额外信息:无。
【问题讨论】:
标签: python google-app-engine logging google-cloud-storage