how to fixJSON Response: {'error': {'code': '404', 'message': 'Resource not found'}}

yananthula 0 Reputation points
2023-08-31T10:53:27.3933333+00:00
import os
import requests
import base64

# Replace with your Bing Image Search API subscription key
subscription_key = '101c04c39baf43ea88ea7d04c9511b90'

# API endpoint for Bing Image Search
bing_image_search_api_url = 'https://api.cognitive.microsoft.com/bing/v7.0/images/search'

# Function to perform reverse image search for an image
def perform_reverse_image_search(image_base64):
    headers = {'Ocp-Apim-Subscription-Key': subscription_key}
    params = {'q': 'imageType=photo&knowledgeRequest=true'}
    data = {'image': image_base64}
    response = requests.post(bing_image_search_api_url, headers=headers, params=params, data=data)
    return response

# Specify the correct path to the uploaded image in Colab environment
image_file_path = '/content/t5pclX.jpg'

# Read the image file as bytes
with open(image_file_path, 'rb') as image_file:
    image_data = image_file.read()

# Encode the image data as base64
image_base64 = base64.b64encode(image_data).decode('utf-8')

# Perform reverse image search using the base64-encoded image data
response = perform_reverse_image_search(image_base64)

# Print the parsed JSON response
try:
    json_response = response.json()
    print("JSON Response:", json_response)
except Exception as e:
    print("Error parsing JSON response:", e)
Microsoft 365 and Office | Install, redeem, activate | For business | Windows
Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,751 Reputation points
    2023-09-01T07:45:53.41+00:00

    Hello there,

    Create a view that should be called if none of the URL patterns match.

    Add handler404 = path.to.your.view to your root URLconf.

    Similar discussion here

    [https://learn.microsoft.com/en-us/answers/questions/1356298/how-to-fixjson-response-((error-((code-404-message ](https://learn.microsoft.com/en-us/answers/questions/1356298/how-to-fixjson-response-((error-((code-404-message )

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    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.