I'm using the GCS client library to write files to Google Cloud Storage in my App Engine app in Python.
Before creating a file, I need to make sure it doesn't already exist to avoid overwriting.
To do this I am checking to see if the file exists before trying to create it:
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() is logging (either directly or indirectly) the fact that it receives a 404 error when trying to read the non-existent file. I would like to suppress this if possible.
Thanks
edit Here's what is logged:
12:19:32.565 suspended generator _get_segment(storage_api.py:432) raised NotFoundError(Expect status [200, 206] from Google Storage. But got status 404. Path: '/cs-mailing/bde24e63-4d31-41e5-8aff-14b76b239388.html'. Request headers: {'Range': 'bytes=0-1048575', 'x-goog-api-version': '2', 'accept-encoding': 'gzip, *'}. Response headers: {'alternate-protocol': '443:quic', 'content-length': '127', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': 'remote-fetch', 'expires': 'Mon, 02 Jun 2014 11:19:32 GMT', 'server': 'HTTP Upload Server Built on May 19 2014 09:31:01 (1400517061)', 'cache-control': 'private, max-age=0', 'date': 'Mon, 02 Jun 2014 11:19:32 GMT', 'content-type': 'application/xml; charset=UTF-8'}. Body: "
NoSuchKey
The specified key does not exist.". Extra info: None.