Azure Computer Vision - detect_objects_in_stream (InvalidRequest) Input data is not a valid image.

Vedant Modi 26 Reputation points
2021-08-27T14:08:30.937+00:00

I need to run Azure Computer Vision on an image via a URL. The URL can only be accessed via a VPN. I'm connected to the VPN when I run this.

im = Image.open(requests.get(path, stream=True).raw)

buffer = io.BytesIO()
im.save(buffer, 'jpeg')
buffer.seek(0)
image = buffer

results = computervision_client.read_in_stream(image, raw=True)
object_results = computervision_client.detect_objects_in_stream(image, raw=True)
operation_location_local = results.headers["Operation-Location"]
operation_id_local = operation_location_local.split("/")[-1]

I get the following error:

Traceback (most recent call last):                                   
  File "path of above code", line 505, in url_detector
    object_results = computervision_client.detect_objects_in_stream(image, raw=True)
  File "c:\snip\azure\cognitiveservices\vision\computervision\operations\_computer_vision_cl
ient_operations.py", line 1263, in detect_objects_in_stream
    raise models.ComputerVisionErrorResponseException(self._deserialize, response)
azure.cognitiveservices.vision.computervision.models._models_py3.ComputerVisionErrorResponseException: (InvalidRequest) Input data is not a valid image.

The problem arises only with detect_objects_in_stream, read_in_stream works perfectly. Where am I going wrong?
I've tried using the im object too. I cannot pass the URL path directly in my case.

Azure Computer Vision
Azure Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
381 questions
Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,921 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.