I get errors when calling the API using base64 image. Here is my code and please let me know if there is any problem. Thanks!
Trial 1:
import base64
import requests
filepath = "./my_image.jpg"
binary_fc = open(filepath, 'rb').read() # fc aka file_content
base64_utf8_str = base64.b64encode(binary_fc).decode('utf-8')
ext = filepath.split('.')[-1]
data = f'data:image/{ext};base64,{base64_utf8_str}'
url = "https://vehicle-make-and-model-recognition.p.rapidapi.com/v1"
files = { "inputimage": data }
headers = {
"content-type": "application/x-www-form-urlencoded",
"X-RapidAPI-Key": my_rapidapi_key,
"X-RapidAPI-Host": "vehicle-make-and-model-recognition.p.rapidapi.com"
}
response = requests.post(url, files=files, headers=headers)
print(response.json())
return:
{'message': 'Parameter error', 'message_key': '78', 'service': 'vmmr', 'status': 'FAILED', 'version': '2.0'}
trial 2:
import base64
import requests
with open("./my_image.jpg", "rb") as image_file:
data = base64.b64encode(image_file.read()).decode('utf-8')
url = "https://vehicle-make-and-model-recognition.p.rapidapi.com/v1"
payload = { "inputimage": data }
headers = {
"content-type": "application/x-www-form-urlencoded",
"X-RapidAPI-Key": my_rapidapi_key,
"X-RapidAPI-Host": "vehicle-make-and-model-recognition.p.rapidapi.com"
}
response = requests.post(url, data=payload, headers=headers)
print(response.json())
return:
{'message': 'Parameter error', 'message_key': '78', 'service': 'vmmr', 'status': 'FAILED', 'version': '2.0'}
Join in the discussion - add comment below:
Sent you the image via email with title “Vehicle Make and Model Recognition Error image” from Hugo.
Can you email me the problematic images (domino.net@gmail.com)?
I ran this code but still got an error.
{'code': '400', 'message': 'Sorry,something was wrong,please try again later.'}
#If it’s a file, look at this example
import requests
url = "https://vehicle-make-and-model-recognition.p.rapidapi.com/v1"
files=[ (‘inputimage’,(’’,open(’/path/sample.jpeg’,‘rb’),‘image/jpeg’)) ]
headers = { “X-RapidAPI-Key”: “Your key”, “X-RapidAPI-Host”: “vehicle-make-and-model-recognition.p.rapidapi.com” }
response = requests.post(url, files=files, headers=headers) print(response.json())
#If it’s a base64 image or url, look at this example
import requests
url = "https://vehicle-make-and-model-recognition.p.rapidapi.com/v1"
payload = {‘inputurl’: ‘data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/…’}
headers = { “X-RapidAPI-Key”: “Your key”, “X-RapidAPI-Host”: “vehicle-make-and-model-recognition.p.rapidapi.com” }
response = requests.post(url, data=payload, headers=headers) print(response.json())
#Please let me know if you have any other questions
#If it’s a file, look at this example
import requests
url = "https://vehicle-make-and-model-recognition.p.rapidapi.com/v1"
files=[
(‘inputimage’,(’’,open(’/path/sample.jpeg’,‘rb’),‘image/jpeg’))
]
headers = {
“X-RapidAPI-Key”: “Your key”,
“X-RapidAPI-Host”: “vehicle-make-and-model-recognition.p.rapidapi.com”
}
response = requests.post(url, files=files, headers=headers)
print(response.json())
#If it’s a base64 image or url, look at this example
import requests
url = "https://vehicle-make-and-model-recognition.p.rapidapi.com/v1"
payload = {‘inputurl’: ‘data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/…’}
headers = {
“X-RapidAPI-Key”: “Your key”,
“X-RapidAPI-Host”: “vehicle-make-and-model-recognition.p.rapidapi.com”
}
response = requests.post(url, data=payload, headers=headers)
print(response.json())
#Please let me know if you have any other questions