从 google 云存储获取状态 503
getting status 503 from google cloud storage
我在使用默认存储桶将图像上传到 google 新创建的应用引擎应用程序的云存储时遇到问题。
我使用的上传代码在部署到已经具有活动默认存储桶的旧应用引擎应用程序时工作得很好。当我创建一个新的应用程序引擎项目或在 appengine.google.com 上激活默认 gcs 存储桶时,我收到一个奇怪的 500 (503) 错误。
我的上传代码使用了 cloudstorage 客户端,如下所示:
def save_to_gcs(file_obj, obj):
# pass a file and a datastore entity to associate the file to
serving_url = ''#just assign it adn reassign later
time_stamp = int(time.time())
app_id = app_identity.get_application_id()
logging.error("got app_id .... %s" % app_id)
fname = '/%s.appspot.com/post_%s_%s.jpg' % (app_id, obj.key.id(), time_stamp)
# logging.error(file_obj)
logging.error("fname .... %s" % fname)
gcs_file = gcs.open(fname, 'w', content_type="image/jpeg")
gcs_file.write(file_obj)
logging.error("written file obj ....")# <-- this is where the logs stop
gcs_file.close()
gcs_filename = "/gs%s" % fname
serving_url = images.get_serving_url(blobstore.create_gs_key(gcs_filename))
logging.error("got serving url ....")
media_obj = save_gcs_to_media(gcs_filename, serving_url, obj)
logging.error("saved media obj ....")
return media_obj
我认为错误与 file.close() 方法有关,可能与默认存储桶有关。
我已通过正确的身份验证,我正在上传的文件大约为 100kb,所以没什么大的。
任何帮助将不胜感激(事实上,它可以防止我的头发先变白,然后再掉)。
抱歉造成混乱,但这是日志:
E 11:05:54.412 - - - - COVER - - - -
E 11:05:54.413 True
E 11:05:54.413 got time stamp
E 11:05:54.413 got time file name
E 11:05:54.413 got app_id .... emile-test
E 11:05:54.413 fname .... /emile-test.appspot.com/post_5629499534213120_1436432754.jpg
E 11:05:54.696 written file obj ....
D 11:05:55.025 Tasklet is <bound method _StorageApi.urlfetch_async of <cloudstorage.storage_api._StorageApi object at 0xfbd7bf10>>
D 11:05:55.025 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9a810> from tasklet.
D 11:05:55.025 Retry in 0.1 seconds.
D 11:05:55.477 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9a9b0> from tasklet.
D 11:05:55.478 Retry in 0.2 seconds.
D 11:05:56.152 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9ab30> from tasklet.
D 11:05:56.153 Retry in 0.4 seconds.
D 11:05:57.244 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9acb0> from tasklet.
D 11:05:57.245 Retry in 0.8 seconds.
D 11:05:58.435 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd7b690> from tasklet.
D 11:05:58.435 Retry in 1.6 seconds.
D 11:06:00.542 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfe4ce630> from tasklet.
D 11:06:00.542 Retry in 3.2 seconds.
D 11:06:04.179 Tasklet failed after 7 attempts and 9.48189997673 seconds in total
**E 11:06:04.180 Expect status [200] from Google Storage. But got status 503.**
Path: '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg'.
Request headers: {'content-range': 'bytes 0-108067/108068', 'x-goog-api-version': '2', 'accept-encoding': 'gzip, *'}.
Response headers: {'content-length': '0', 'x-guploader-uploadid': 'AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
Body: ''.
Extra info: {'upload_path': '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg?upload_id=AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/main.py", line 757, in post
media_obj = utils.save_to_gcs(image, post)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/utils.py", line 131, in save_to_gcs
gcs_file.close()
**File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/storage_api.py", line 750, in close**
self._flush(finish=True)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/storage_api.py", line 804, in _flush
self._send_data(data, self._written, file_len)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/storage_api.py", line 837, in _send_data
{'upload_path': self._path_with_token})
File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/errors.py", line 141, in check_status
raise ServerError(msg)
ServerError: Expect status [200] from Google Storage. But got status 503.
Path: '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg'.
Request headers: {'content-range': 'bytes 0-108067/108068', 'x-goog-api-version': '2', 'accept-encoding': 'gzip, *'}.
Response headers: {'content-length': '0', 'x-guploader-uploadid': 'AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
Body: ''.
Extra info: {'upload_path': '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg?upload_id=AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
我今天在我自己的 GAE 项目中修复了这个问题(相同的堆栈跟踪)(我正在从 blobstore 中的文件 API 迁移到 cloudstorage)。我采取的步骤是:
进入 Google 开发者控制台
https://console.developers.google.com/project/YOUR_APP_ID/storage/browser
其中 YOUR_APP_ID 是不带 .appspot.com 后缀的应用名称,例如 'foo',而不是 'foo.appspot.com',
点击了我项目右侧的三个垂直点
选定的存储桶权限
将我的电子邮件地址添加为 Entity=User, name=myemail@gmail.com, Access=Owner.
我不是 100% 确定为什么这会解决问题,但它已经成功了。
我在使用默认存储桶将图像上传到 google 新创建的应用引擎应用程序的云存储时遇到问题。
我使用的上传代码在部署到已经具有活动默认存储桶的旧应用引擎应用程序时工作得很好。当我创建一个新的应用程序引擎项目或在 appengine.google.com 上激活默认 gcs 存储桶时,我收到一个奇怪的 500 (503) 错误。
我的上传代码使用了 cloudstorage 客户端,如下所示:
def save_to_gcs(file_obj, obj):
# pass a file and a datastore entity to associate the file to
serving_url = ''#just assign it adn reassign later
time_stamp = int(time.time())
app_id = app_identity.get_application_id()
logging.error("got app_id .... %s" % app_id)
fname = '/%s.appspot.com/post_%s_%s.jpg' % (app_id, obj.key.id(), time_stamp)
# logging.error(file_obj)
logging.error("fname .... %s" % fname)
gcs_file = gcs.open(fname, 'w', content_type="image/jpeg")
gcs_file.write(file_obj)
logging.error("written file obj ....")# <-- this is where the logs stop
gcs_file.close()
gcs_filename = "/gs%s" % fname
serving_url = images.get_serving_url(blobstore.create_gs_key(gcs_filename))
logging.error("got serving url ....")
media_obj = save_gcs_to_media(gcs_filename, serving_url, obj)
logging.error("saved media obj ....")
return media_obj
我认为错误与 file.close() 方法有关,可能与默认存储桶有关。
我已通过正确的身份验证,我正在上传的文件大约为 100kb,所以没什么大的。
任何帮助将不胜感激(事实上,它可以防止我的头发先变白,然后再掉)。
抱歉造成混乱,但这是日志:
E 11:05:54.412 - - - - COVER - - - -
E 11:05:54.413 True
E 11:05:54.413 got time stamp
E 11:05:54.413 got time file name
E 11:05:54.413 got app_id .... emile-test
E 11:05:54.413 fname .... /emile-test.appspot.com/post_5629499534213120_1436432754.jpg
E 11:05:54.696 written file obj ....
D 11:05:55.025 Tasklet is <bound method _StorageApi.urlfetch_async of <cloudstorage.storage_api._StorageApi object at 0xfbd7bf10>>
D 11:05:55.025 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9a810> from tasklet.
D 11:05:55.025 Retry in 0.1 seconds.
D 11:05:55.477 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9a9b0> from tasklet.
D 11:05:55.478 Retry in 0.2 seconds.
D 11:05:56.152 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9ab30> from tasklet.
D 11:05:56.153 Retry in 0.4 seconds.
D 11:05:57.244 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd9acb0> from tasklet.
D 11:05:57.245 Retry in 0.8 seconds.
D 11:05:58.435 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfbd7b690> from tasklet.
D 11:05:58.435 Retry in 1.6 seconds.
D 11:06:00.542 Got result <google.appengine.api.urlfetch._URLFetchResult object at 0xfe4ce630> from tasklet.
D 11:06:00.542 Retry in 3.2 seconds.
D 11:06:04.179 Tasklet failed after 7 attempts and 9.48189997673 seconds in total
**E 11:06:04.180 Expect status [200] from Google Storage. But got status 503.**
Path: '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg'.
Request headers: {'content-range': 'bytes 0-108067/108068', 'x-goog-api-version': '2', 'accept-encoding': 'gzip, *'}.
Response headers: {'content-length': '0', 'x-guploader-uploadid': 'AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
Body: ''.
Extra info: {'upload_path': '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg?upload_id=AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/main.py", line 757, in post
media_obj = utils.save_to_gcs(image, post)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/utils.py", line 131, in save_to_gcs
gcs_file.close()
**File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/storage_api.py", line 750, in close**
self._flush(finish=True)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/storage_api.py", line 804, in _flush
self._send_data(data, self._written, file_len)
File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/storage_api.py", line 837, in _send_data
{'upload_path': self._path_with_token})
File "/base/data/home/apps/s~emile-test/1.385589451941224330/cloudstorage/errors.py", line 141, in check_status
raise ServerError(msg)
ServerError: Expect status [200] from Google Storage. But got status 503.
Path: '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg'.
Request headers: {'content-range': 'bytes 0-108067/108068', 'x-goog-api-version': '2', 'accept-encoding': 'gzip, *'}.
Response headers: {'content-length': '0', 'x-guploader-uploadid': 'AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
Body: ''.
Extra info: {'upload_path': '/emile-test.appspot.com/post_5629499534213120_1436432754.jpg?upload_id=AEnB2UqzyZwtoNSy8sTEUq7a8fai-A5aDVlMccCj1UVEo72NAUUw4kyDotehcf8RDusUzm52092rdO0CR9JxIC9ba1J5Kj1xuw'}.
我今天在我自己的 GAE 项目中修复了这个问题(相同的堆栈跟踪)(我正在从 blobstore 中的文件 API 迁移到 cloudstorage)。我采取的步骤是:
进入 Google 开发者控制台
https://console.developers.google.com/project/YOUR_APP_ID/storage/browser
其中 YOUR_APP_ID 是不带 .appspot.com 后缀的应用名称,例如 'foo',而不是 'foo.appspot.com',
点击了我项目右侧的三个垂直点
选定的存储桶权限
将我的电子邮件地址添加为 Entity=User, name=myemail@gmail.com, Access=Owner.
我不是 100% 确定为什么这会解决问题,但它已经成功了。