简体   繁体   English

结合使用Blobstore API和Google Cloud Storage-http 404错误消息

[英]Using the Blobstore API with Google Cloud Storage - http 404 error message

Today if an url is incorrect, users get this display from my appengine instance: 今天,如果网址不正确,则用户可以从我的appengine实例获得以下显示:

Error: Server Error

The server encountered an error and could not complete your request.
Please try again in 30 seconds.

I found this reference on how to address with a proper 404 message using the blobstore.get, but unfortunately it's not working. 我找到了有关如何使用blobstore.get使用正确的404消息进行寻址的参考 ,但不幸的是,该参考无法正常工作。 I figured out why. 我弄清楚了原因。 The bkey always returns some value, so it will always think "its not a invalid bkey". bkey始终返回一些值,因此它将始终认为“它不是无效的bkey”。 What I'm trying to figure out is how to write the code in the case that the bkey is invalid. 我要弄清楚的是在bkey无效的情况下如何编写代码。 Below is my code: 下面是我的代码:

gs_filename = '/gs/%s/%s' % (settings.BUCKET, filename)
bkey = blobstore.create_gs_key(gs_filename)

if not blobstore.get(key):
   logging.info("I got a 404 error'")
else:
  return blobstore_dh.send_blob(bkey, content_type=ct)

Does anyone have any suggestions? 有没有人有什么建议?

I just ran into this as well and came up with a quick workaround: 我也遇到了这个问题,并提出了一个快速的解决方法:

from google.appengine.api.blobstore import BlobNotFoundError

..

    try:
        blobstore.BlobReader(blob_key).read(1)
    except BlobNotFoundError:
        logging.info('BlobNotFoundError')
        self.abort(404)

Does feel a bit hackish, so if anybody finds a better way, I would love to hear about it! 确实感觉有点骇人听闻,所以如果有人找到更好的方法,我很想听听它!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine-将Blobstore API与Google Cloud Storage结合使用 - Google App Engine - Using Blobstore API with Google Cloud Storage 说明 - 使用 Blobstore API 将图像/视频上传到 Google Cloud Storage - Clarification - using Blobstore API to upload images/videos to Google Cloud Storage 在 Google Cloud Function 中为 Google Cloud Storage 使用 compose 时出现 404 错误 - 404 Error using compose for Google Cloud Storage in Google Cloud Function 使用Python Blobstore API上传文件时选择Google Cloud Storage对象名称 - Choosing Google Cloud Storage object name when uploading a file using Python blobstore API 使用Google云端存储时出错 - Error using Google Cloud Storage 无法使用python将文件上传到Google云存储 - 得到404错误 - Unable to upload file to Google cloud storage using python - get a 404 error 将Google Cloud Storage与GAE远程API配合使用 - Using Google Cloud Storage with GAE remote API 在本地主机上使用Google Cloud Storage JSON API - Using Google Cloud Storage JSON API on localhost Google Speech API无法在Google Storage上找到文件:错误404 - Google Speech API unable to find a file on Google Storage: error 404 谷歌应用引擎; 上传到blobstore会出现404错误 - google app engine; upload to blobstore gives 404 error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM