mistralai / client-python

Python client library for Mistral AI platform
Apache License 2.0
469 stars 97 forks source link

Problem getting the response status text in all exceptions #77

Closed dbrewster closed 1 month ago

dbrewster commented 6 months ago

In all of the following constructors to the exception, there is a error calling response.text:

async def _check_response_status_codes(self, response: Response) -> None: if response.status_code in RETRY_STATUS_CODES: raise MistralAPIStatusException.from_response( response, message=f"Status: {response.status_code}. Message: {response.text}", ) elif 400 <= response.status_code < 500: if response.stream: await response.aread() raise MistralAPIException.from_response( response, message=f"Status: {response.status_code}. Message: {response.text}", ) elif response.status_code >= 500: if response.stream: await response.aread() raise MistralException( message=f"Status: {response.status_code}. Message: {response.text}", )

File "/Users/apple/opt/anaconda3/envs/rena-sanic-39/lib/python3.9/site-packages/mistralai/client_base.py", line 137, in _check_response_status_codes message=f"Status: {response.status_code}. Message: {response.text}", File "/Users/apple/opt/anaconda3/envs/rena-sanic-39/lib/python3.9/site-packages/httpx/_models.py", line 573, in text content = self.content File "/Users/apple/opt/anaconda3/envs/rena-sanic-39/lib/python3.9/site-packages/httpx/_models.py", line 567, in content raise ResponseNotRead() httpx.ResponseNotRead: Attempted to access streaming response content, without having called read().

sophiamyang commented 1 month ago

This should be fixed. Could you try mistralai 1.0.0 and let us know if you still see the issue? Thanks!