gpt4 book ai didi

python - Google 图片 APIexecute_transforms() 返回 "there has been an error"

转载 作者:行者123 更新时间:2023-12-01 01:03:16 25 4
gpt4 key购买 nike

我正在尝试使用 Google 的图像处理 API。这看起来非常简单,但是当我在 Image 对象上调用 execute_transforms 时,它会抛出一个通用的“存在错误”

gcs_file_location 是正确的,在我调用execute_transforms() 之前不会抛出任何错误。图片文件不要太大。

from google.appengine.api import images


gcs_file_location = '/gs/' + gcs_file_location
img = images.Image(filename=gcs_file_location)
img.resize(width=50, height=50)

# The following code throws "There has been an error"
thumbnail = img.execute_transforms()

最佳答案

我花了一段时间,但我成功地复制了您的场景,因此我设置了一个 Python 2.7 环境(根据 Images Python API Overview 的教程)并使用 Django 设置所需的所有文件official repository 中的代码,并在 Django 的 official tutorial 的帮助下运行它。

然后,我修改了服务轮询以执行引发这些错误的函数。

def index(request):
filename_gs=request.GET.get("id")
img = images.Image(filename=filename_gs)
img.resize(width=1000, height=1000)
thumbnail = img.execute_transforms()

我发现你确实是对的,在函数 execute_transforms 中引发错误并停止执行。但是,我没有遇到您提到的一般错误,我收到以下信息:

  File "/home/polortiz/DJANGOOO/mytry3/python-docs-samples/appengine/standard/django/polls/views.py", line 48, in index
thumbnail = img.execute_transforms()
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/images/__init__.py", line 810, in execute_transforms
return rpc.get_result()
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 615, in get_result
return self.__get_result_hook(self)
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/images/__init__.py", line 898, in execute_transforms_hook
raise _ToImagesError(e, self._blob_key)
TransformationError

我进一步调查,以检查哪些问题可能引发这些错误,并发现 library code of that function 。在那里你可以看到引发的所有异常:

  • BadRequestError: When the request specifications are invalid.
  • NotImageError: When the image data given is not an image.
  • BadImageError: When the image data given is corrupt.
  • LargeImageError: When the image data given is too large to process.
  • InvalidBlobKeyError: When the blob key provided is invalid.
  • TransformationError: When an error occurs during image manipulation.
  • AccessDeniedError: When the blob key refers to a Google Storage object, and the application does not have permission to access the object.
  • ObjectNotFoundError: When the blob key refers to an object that no longer exists.

因此,为了解决您的问题,最好检查所有这些要点。回答评论中提出的问题:

Is django not compatible with Google's Imaging API or do I need to import WebApp2?

Google 的成像 API 与 Django 兼容。并且并不强制使用 WebApp2 来处理 http 请求和响应。

关于python - Google 图片 APIexecute_transforms() 返回 "there has been an error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55602893/

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