[英]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.