MCPcopy Create free account
hub / github.com/modelscope/modelscope / raise_for_http_status

Function raise_for_http_status

modelscope/hub/errors.py:212–249  ·  view source on GitHub ↗

Attempt to decode utf-8 first since some servers localize reason strings, for invalid utf-8, fall back to decoding with iso-8859-1. Args: rsp: The http response. Raises: HTTPError: The http error info.

(rsp)

Source from the content-addressed store, hash-verified

210
211
212def raise_for_http_status(rsp):
213 """Attempt to decode utf-8 first since some servers
214 localize reason strings, for invalid utf-8, fall back
215 to decoding with iso-8859-1.
216
217 Args:
218 rsp: The http response.
219
220 Raises:
221 HTTPError: The http error info.
222 """
223 http_error_msg = ''
224 if isinstance(rsp.reason, bytes):
225 try:
226 reason = rsp.reason.decode('utf-8')
227 except UnicodeDecodeError:
228 reason = rsp.reason.decode('iso-8859-1')
229 else:
230 reason = rsp.reason
231 request_id = get_request_id(rsp)
232 if 404 == rsp.status_code:
233 http_error_msg = 'The request resource(model or dataset) does not exist!,'
234 'url: %s, reason: %s' % (rsp.url, reason)
235 elif 403 == rsp.status_code:
236 http_error_msg = 'Authentication token does not exist or invalid.'
237 elif 400 <= rsp.status_code < 500:
238 http_error_msg = u'%s Client Error: %s, Request id: %s for url: %s' % (
239 rsp.status_code, reason, request_id, rsp.url)
240
241 elif 500 <= rsp.status_code < 600:
242 http_error_msg = u'%s Server Error: %s, Request id: %s, for url: %s' % (
243 rsp.status_code, reason, request_id, rsp.url)
244
245 if http_error_msg:
246 req = rsp.request
247 if req.method == 'POST':
248 http_error_msg = u'%s, body: %s' % (http_error_msg, req.body)
249 raise HTTPError(http_error_msg, response=rsp)

Callers 7

list_mcp_serversMethod · 0.90
get_mcp_serverMethod · 0.90
createMethod · 0.90
getMethod · 0.90
deleteMethod · 0.90
listMethod · 0.90

Calls 2

get_request_idFunction · 0.85
decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…