cloudy_vision
cloudy_vision copied to clipboard
cloudsight.errors.APIError: Invalid byte sequence - Cloudsight API
I'm getting an error using Cloudsight API, on windows.
Traceback (most recent call last):
File "cloudy_vision.py", line 264, in <module>
process_all_images()
File "cloudy_vision.py", line 198, in process_all_images
api_result = vendor_module.call_vision_api(filepath, settings('api_keys'))
File "C:\Users\EdanWeis\Documents\cloudy_vision\vendors\cloudsight_.py", line 14, in call_vision_api
response = api.image_request(image_file, image_filename)
File "C:\Python27\lib\site-packages\cloudsight\api.py", line 114, in image_request
return self._unwrap_error(response)
File "C:\Python27\lib\site-packages\cloudsight\api.py", line 88, in _unwrap_error
raise errors.APIError(json_response['error'])
cloudsight.errors.APIError: Invalid byte sequence
Any suggestions? I've contacted Cloudsight for comment.
Looks like an encoding issue with you image. Maybe due to windows format or your version of python.
Can you attach the image you are using so we can reproduce?
I have the same problem here. I use Windows 10 and this is the image: https://dafitistatic-a.akamaihd.net/p/Colcci-Camiseta-Colcci-Bordado-Amarela-7538-2489802-1-zoom.jpg Tried with other images too, but still the same error.
Traceback (most recent call last): File "cloudy_vision.py", line 264, in
process_all_images() File "cloudy_vision.py", line 198, in process_all_images api_result = vendor_module.call_vision_api(filepath, settings('api_keys')) File "C:\Users\stammg\Downloads\cloudy_vision-master\cloudy_vision-master\vendors\cloudsight_.py", line 14, in call_vision_api response = api.image_request(image_file, image_filename) File "C:\Python27\lib\site-packages\cloudsight\api.py", line 114, in image_request return self._unwrap_error(response) File "C:\Python27\lib\site-packages\cloudsight\api.py", line 88, in _unwrap_error raise errors.APIError(json_response['error']) cloudsight.errors.APIError: invalid byte sequence in UTF-8
Found a solution; In the cloudsight\api.py, the line 113, change this; data=data, files={'image_request[image]': (filename, image)})
to this; data=data, files={'image_request[image]': image})
problem solved here!
Hi, I use cloudsight for my android app, and i receive error 500. any solution for this?
private String uploadData(String url) {
String sResponse = "";
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httppost = new HttpPost(url+"/images");
httppost.addHeader("Content-Type", "application/json");
httppost.addHeader("Authorization", "CloudSight APIKEY");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 60, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
String image = Base64.encodeToString(byteArray, Base64.DEFAULT);
JSONObject obj = new JSONObject();
Log.i("", image);
obj.put("remote_image_url",image);
obj.put("locale", "en");
httppost.setEntity(new StringEntity(obj.toString()));
HttpResponse response = httpClient.execute(httppost, localContext);
int responseCode = response.getStatusLine().getStatusCode();
sResponse = inputStreamToString(
response.getEntity().getContent()).toString();
Log.i("ResponseString", sResponse);
Log.i("code", responseCode+"");
} catch (Exception ex) {
ex.printStackTrace();
}
return sResponse;
}