@@ -74,6 +74,10 @@ def __init__(
7474
7575 def __str__ (self ):
7676 """Return the Response data if object is converted to a string."""
77+ if isinstance (self .data , bytes ):
78+ raise ValueError (
79+ "As the response.data is binary data, this operation is unsupported"
80+ )
7781 return f"{ self .data } "
7882
7983 def __getitem__ (self , key ):
@@ -87,6 +91,14 @@ def __getitem__(self, key):
8791 Returns:
8892 The value from data or None.
8993 """
94+ if isinstance (self .data , bytes ):
95+ raise ValueError (
96+ "As the response.data is binary data, this operation is unsupported"
97+ )
98+ if self .data is None :
99+ raise ValueError (
100+ "As the response.data is empty, this operation is unsupported"
101+ )
90102 return self .data .get (key , None )
91103
92104 def __aiter__ (self ):
@@ -156,6 +168,12 @@ def get(self, key, default=None):
156168 Returns:
157169 The value from data or the specified default.
158170 """
171+ if isinstance (self .data , bytes ):
172+ raise ValueError (
173+ "As the response.data is binary data, this operation is unsupported"
174+ )
175+ if self .data is None :
176+ return None
159177 return self .data .get (key , default )
160178
161179 def validate (self ):
@@ -168,13 +186,6 @@ def validate(self):
168186 Raises:
169187 SlackApiError: The request to the Slack API failed.
170188 """
171- if self ._logger .level <= logging .DEBUG :
172- self ._logger .debug (
173- "Received the following response - "
174- f"status: { self .status_code } , "
175- f"headers: { dict (self .headers )} , "
176- f"body: { self .data } "
177- )
178189 if self .status_code == 200 and self .data and self .data .get ("ok" , False ):
179190 return self
180191 msg = "The request to the Slack API failed."
0 commit comments