@@ -26,6 +26,8 @@ def error_for(self, status_code, parsed): # noqa: C901
2626 return NotFoundError
2727 if status_code >= 400 :
2828 return ClientError
29+ if status_code == 204 :
30+ return None
2931 if not parsed :
3032 return ParserError
3133
@@ -44,7 +46,14 @@ def _parse_data(self, client):
4446 self .result = None
4547 self .headers = {}
4648
47- self .__parse_body_and_headers (self .http_response , client )
49+ self .__parse_headers (self .http_response , client )
50+
51+ # Avoid parsing body in 204 responses
52+ if self .status_code == 204 :
53+ return
54+
55+ self .__parse_body (self .http_response , client )
56+
4857 self .result = self .__parse_json (client )
4958 if (self .result is not None ):
5059 self .data = self .result .get ('data' , None )
@@ -57,12 +66,14 @@ def __raise_error(self, error_class, client):
5766 error ._log (client )
5867 raise error
5968
60- # Extract the body and headers
61- def __parse_body_and_headers (self , http_response , client ):
69+ def __parse_headers (self , http_response , client ):
6270 if hasattr (http_response , 'getheaders' ):
6371 self .headers = dict (http_response .getheaders ()) or self .headers
6472 if hasattr (http_response , 'info' ):
6573 self .headers = http_response .info () or self .headers
74+
75+ # Extract the body and headers
76+ def __parse_body (self , http_response , client ):
6677 if hasattr (http_response , 'read' ):
6778 self .body = http_response .read ()
6879 if hasattr (self .body , 'decode' ):
0 commit comments