why am i getting this error?

Singh, Shruti 20 Reputation points
2024-03-26T09:26:35.4066667+00:00

I have written thos code to read my image but it is giving me error . the code is-

service_options = ImageAnalysisClient(
    endpoint=endpoint,
    credential=AzureKeyCredential(key)
)

# document_file_path = r"C:\Users\sivasurya.jawaharji\Downloads\doc_with_smartart.pdf"

def computer_vision_service(file_path):

    result = service_options.analyze_from_url(image_url=file_path, visual_features=[VisualFeatures.CAPTION, VisualFeatures.READ], gender_neutral_caption=True,
        )

    Line_list = []
    Word_list = []

    if result.read is not None:
        for line in result.read.blocks[0].lines:
            print(f"   Line: '{line.text}', Bounding box {line.bounding_polygon}")
            for word in line.words:
                print(
                    f"     Word: '{word.text}', Bounding polygon {word.bounding_polygon}, Confidence {word.confidence:.4f}")

the error is-
raise HttpResponseError(response=response)
azure.core.exceptions.HttpResponseError: (InvalidRequest) The provided image url is not valid.
Code: InvalidRequest
Message: The provided image url is not valid.
(InvalidRequest) The provided image url is not valid.
Code: InvalidRequest
Message: The provided image url is not valid.

my image url is /Users/shrutisingh/Documents/django/Hello/Azure_Unscrubbed/AP322_Configuration Document_Candidate_Prescreening/word/media/image9.png

what could be the error? can u please tell me

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
3,628 questions
{count} votes

Accepted answer
  1. santoshkc 15,355 Reputation points Microsoft External Staff Moderator
    2024-03-29T06:15:29.1933333+00:00

    Hi @Singh, Shruti,

    Glad to know that your issue has been resolved. And thanks for sharing the solution, which might be beneficial to other community members reading this thread. Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer.

    Question: why am i getting this error?

    Answer: I found the solution on Microsoft page itself. I replaced the parameter image_url with image data. where image_data is:

    with open(file_path, "rb") as f:
        image_data = f.read()
    

    Thank you.


    Please do click Accept Answer and Yes for was this answer helpful.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Singh, Shruti 20 Reputation points
    2024-03-29T05:24:33.0433333+00:00

    Hi @santoshkc ,

    I found the solution on Microsoft page itself. I replaced the parameter image_url with image data. where image_data is

    with open(file_path, "rb") as f:
        image_data = f.read()
    

    Thanks and regards,

    Shruti

    0 comments No comments

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.