[英]Google App Engine, Cloud Storage can't read uploaded files in python
I created the bucket, upload a file via 我创建了存储桶,通过上传文件
gsutil cp -a public-read test.htm gs://BUCKETNAME
I can see the file in the Storage Browser and with gsutil ls 我可以在Storage Browser和gsutil ls中看到该文件
When I try to read it with the following code, I get 当我尝试使用以下代码阅读时,我得到
NotFoundError: Expect status [200] from Google Storage. NotFoundError:预期Google存储状态为[200]。 But got status 404. 但是状态为404。
Code: 码:
import logging
import os
import lib.cloudstorage as gcs
import webapp2
from google.appengine.api import app_identity
my_default_retry_params = gcs.RetryParams(initial_delay=0.2,
max_delay=5.0,
backoff_factor=2,
max_retry_period=50)
gcs.set_default_retry_params(my_default_retry_params)
class MainPage(webapp2.RequestHandler):
def get(self):
bucket_name = os.environ.get('BUCKET_NAME',
app_identity.get_default_gcs_bucket_name())
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Demo GCS Application running from Version: '
+ os.environ['CURRENT_VERSION_ID'] + '\n')
self.response.write('Using bucket name: ' + bucket_name + '\n\n')
bucket = '/' + bucket_name
filename = bucket + '/test.htm'
self.read_file(filename)
def read_file(self, filename):
self.response.write('Abbreviated file content (first line and last 1K):\n')
gcs_file = gcs.open(filename)
self.response.write(gcs_file)
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
Strage thing happens, when I use the sample code from here ( https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/python/demo/main.py ) in my environment. 当我在环境中使用此处的示例代码( https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/python/demo/main.py )时,发生了一些事情。
The code creates and writes a file on the same bucket, then reads it and deletes it. 该代码在同一存储桶中创建和写入文件,然后读取并删除该文件。 Works fine, but when I comment out the delete parts, I can not see the files in Storage Browser or with gsutil, but I can still read them with the code. 工作正常,但是当我注释掉删除部分时,在存储浏览器或gsutil中看不到文件,但仍可以通过代码读取它们。
I checked my bucket permissions in Storage Browser and they seem fine, the service account of the app is bucket owner. 我在存储浏览器中检查了存储桶权限,它们看起来不错,该应用程序的服务帐户是存储桶所有者。
Any help is greatly appreciated. 任何帮助是极大的赞赏。
After revisiting this, due to recent demand I figured it out. 在重新考虑之后,由于最近的需求,我想出了办法。 gsutil has a bug, I read about its somewhere at github. gsutil有一个错误,我在github的某处读到了它。 When I upload the file via storage browser or the python client libraries it works. 当我通过存储浏览器或python客户端库上传文件时,它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.