@@ -83,7 +83,7 @@ def _handle_success(
8383 return model_class (decoded_body ) # type: ignore
8484
8585 def _exception_for_error (
86- self , status : int , content_type : str , raw_body : str , uri : str
86+ self , status : int , content_type : Optional [ str ] , raw_body : str , uri : str
8787 ) -> Union [
8888 AuthenticationError ,
8989 InsufficientFundsError ,
@@ -100,7 +100,7 @@ def _exception_for_error(
100100 return self ._exception_for_unexpected_status (status , raw_body , uri )
101101
102102 def _exception_for_4xx_status (
103- self , status : int , content_type : str , raw_body : str , uri : str
103+ self , status : int , content_type : Optional [ str ] , raw_body : str , uri : str
104104 ) -> Union [
105105 AuthenticationError ,
106106 InsufficientFundsError ,
@@ -113,7 +113,7 @@ def _exception_for_4xx_status(
113113 return HTTPError (
114114 f"Received a { status } error with no body" , status , uri , raw_body
115115 )
116- if content_type .find ("json" ) == - 1 :
116+ if content_type is None or content_type .find ("json" ) == - 1 :
117117 return HTTPError (
118118 f"Received a { status } with the following body: { raw_body } " ,
119119 status ,
@@ -618,7 +618,7 @@ def report(self, report: Dict[str, Optional[str]], validate: bool = True) -> Non
618618
619619 response = self ._do_request (uri , prepared_request )
620620 status = response .status_code
621- content_type = response .headers [ "Content-Type" ]
621+ content_type = response .headers . get ( "Content-Type" )
622622 raw_body = response .text
623623 if status != 204 :
624624 raise self ._exception_for_error (status , content_type , raw_body , uri )
@@ -636,7 +636,7 @@ def _response_for(
636636
637637 response = self ._do_request (uri , prepared_request )
638638 status = response .status_code
639- content_type = response .headers [ "Content-Type" ]
639+ content_type = response .headers . get ( "Content-Type" )
640640 raw_body = response .text
641641 if status != 200 :
642642 raise self ._exception_for_error (status , content_type , raw_body , uri )
0 commit comments