Skip to content

Commit

Permalink
chore: add headers as optional parameter to face selfie
Browse files Browse the repository at this point in the history
  • Loading branch information
acostapazo committed Dec 20, 2023
1 parent 35a004e commit 37b4177
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions alice/face/face.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Dict, Union

from meiga import Failure, Result, Success
from requests import Response, Session
Expand Down Expand Up @@ -50,10 +50,14 @@ def selfie(
media: bytes,
extract_face_pad: bool = True,
extract_face_profile: bool = True,
headers: Union[Dict[str, str], None] = None,
) -> Result[SelfieResult, FaceError]:
if headers is None:
headers = {}

response = self.session.post(
url=f"{self.url}/selfie",
headers={"apikey": self.api_key},
headers={"apikey": self.api_key} | headers,
files={"media": media},
data={
"extract_face_pad": extract_face_pad,
Expand Down
8 changes: 6 additions & 2 deletions alice/face/face_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,20 @@ class MatchResult(BaseModel):


class FaceError(Error):
def __init__(self, message: str, status_code: int):
def __init__(self, message: str, status_code: int, url: str):
self.message = message
self.status_code = status_code
self.url = url

@staticmethod
def from_response(response: Response) -> "FaceError":
return FaceError(
message=str(response.content),
status_code=response.status_code,
url=response.url,
)

def __repr__(self) -> str:
return f"{self.__class__.__name__}: {self.status_code} {self.message}"
return (
f"{self.__class__.__name__}: {self.status_code} {self.message} | {self.url}"
)

0 comments on commit 37b4177

Please sign in to comment.