【问题标题】:Suppress logging by cloudstorage.open() in google app engine GCS client library Python在谷歌应用引擎 GCS 客户端库 Python 中通过 cloudstorage.open() 抑制日志记录
【发布时间】: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


    【解决方案1】:

    您的案例中的日志记录是由 str(e) 触发的。 问题已在https://code.google.com/p/appengine-gcs-client/source/detail?r=172 中修复

    【讨论】:

    • 感谢您的回答。我不明白 str(e) 如何触发日志记录?我删除了它,但记录仍在继续。您链接的修订版会很快成为标准 SDK 的一部分,还是我必须自己更新代码?后者我不太舒服。
    • 此代码作为库提供,而不是 AppEngine SDK 的一部分。因此,您应该将您的代码更新到最新版本:code.google.com/p/appengine-gcs-client 没有太多文件,我认为与您可能正在使用的版本没有太多差异。
    猜你喜欢
    • 1970-01-01
    • 2012-05-25
    • 2011-01-24
    • 2011-05-18
    • 2015-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多