Warm tip: This article is reproduced from stackoverflow.com, please click
google-app-engine google-cloud-storage image python

Google Images API's execute_transforms() returning "there has been an error"

发布于 2020-04-07 23:18:57

I'm trying to use Google's Image Manipulation API. It seems pretty straightforward, but when I call execute_transforms on the Image object, it throws a generic "There has been an error"

The gcs_file_location is correct, no errors get thrown until I call execute_transforms(). The image file is not too large.

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()    
Questioner
Antoine Vo
Viewed
56
Pol Ortiz 2019-04-24 20:44

It took me a while but I managed to replicate your scenario, so I set up a Python 2.7 environment (according to the tutorial for the Images Python API Overview and set all the files needed for Django using the code from the official repository and running it with the help of the official tutorial for Django.

Then, I modified the service polls in order to execute the functions that are raising those errors.

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()

And I found that indeed you are right, in the function execute_transforms raises and error and stops the execution. However, I did not have the generic error that you are referring to, I'm getting the following:

  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

I investigated further in order to check which could be the problems that raises those errors, and found the library code of that function. There you could see all the exception that raises:

  • 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.

So, in order to solve your problem would be great to check all those points. Answering to the questions asked on the comments:

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

Google's Imaging API is compatible with Django. And it is not mandatory to use WebApp2 in order to handle http requests and responses.