Skip to content

Commit

Permalink
Fix content type might not be in headers (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
maingoh authored Mar 30, 2020
1 parent d6b467a commit f479724
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions deepomatic/api/http_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def make_request(self, func, resource, params=None, data=None,
# If no files are provided, requests will default to form-urlencoded content type
# But the API doesn't support it.
if not files:
raise Exception("Cannot send the request as multipart without files provided.")
raise DeepomaticException("Cannot send the request as multipart without files provided.")
# requests will build the good multipart content types with the boundaries
content_type = None
data = self.dump_json_for_multipart(data)
Expand Down Expand Up @@ -299,7 +299,7 @@ def make_request(self, func, resource, params=None, data=None,
# we asked for a stream, we let the user download it as he wants or it will load everything in RAM
# not good for big files
return response
elif 'application/json' in response.headers['Content-Type']:
elif 'application/json' in response.headers.get('Content-Type', ''):
return response.json()
else:
return response.content
Expand Down
2 changes: 1 addition & 1 deletion deepomatic/api/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, source, encoding=None):
self._need_multipart = is_file or (is_raw and encoding == 'binary')

def get_input(self):
raise Exception("Unimplemented")
raise NotImplementedError()

def need_multipart(self):
return self._need_multipart
Expand Down
5 changes: 3 additions & 2 deletions deepomatic/api/resources/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
import functools
import logging

from deepomatic.api.exceptions import TaskError, TaskTimeout, HTTPRetryError, TaskRetryError
from deepomatic.api.exceptions import (TaskError, TaskTimeout, HTTPRetryError,
TaskRetryError, DeepomaticException)
from deepomatic.api.mixins import ListableResource
from deepomatic.api.resource import Resource
from deepomatic.api.utils import retry, warn_on_http_retry_error
Expand Down Expand Up @@ -119,7 +120,7 @@ def _refresh_tasks_status(self, pending_tasks, success_tasks, error_tasks, posit
elif is_success_status(status):
success_tasks.append((pos, task))
else:
raise Exception("Unknown task status %s" % status)
raise DeepomaticException("Unknown task status %s" % status)

return pending_tasks

Expand Down

0 comments on commit f479724

Please sign in to comment.