gpt4 book ai didi

python - 从谷歌云存储获取状态503

转载 作者:太空宇宙 更新时间:2023-11-03 17:35:02 25 4
gpt4 key购买 nike

我在使用默认存储桶将图像上传到新创建的 App Engine 应用中的 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)。我采取的步骤是:

  1. 前往 Google 开发者控制台

    https://console.developers.google.com/project/YOUR_APP_ID/storage/browser

    其中 YOUR_APP_ID 是不带 .appspot.com 后缀的应用程序名称,例如“foo”,而不是“foo.appspot.com”,

  2. 单击我的项目右侧的三个垂直点

  3. 选定的存储桶权限

  4. 将我的电子邮件地址添加为 Entity=User、name=myemail@gmail.com、Access=Owner。

我不是 100% 确定为什么这可以解决问题,但它已经解决了问题。

关于python - 从谷歌云存储获取状态503,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31313441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com