Hi,
I’m trying to download a csv (or excel) file from the results of using the Assistants API in a Jupyter notebook. I’m using the following:
fileContent = client.files.retrieve_content(
file_id=file.id
)
But, I get the following error:
BadRequestError Traceback (most recent call last)
Cell In[221], line 1
----> 1 fileContent = client.files.retrieve_content(
2 file_id=‘file-EP6HIHRTp4EDuHUByZjSDFXF’
3 )
File ~\miniconda3\envs\openai_assistants_dev\Lib\site-packages\openai\resources\files.py:224, in Files.retrieve_content(self, file_id, extra_headers, extra_query, extra_body, timeout)
211 “”"
212 Returns the contents of the specified file.
213
(…)
221 timeout: Override the client-level default timeout for this request, in seconds
222 “”"
223 extra_headers = {“Accept”: “application/json”, **(extra_headers or {})}
→ 224 return self._get(
225 f"/files/{file_id}/content",
226 options=make_request_options(
227 extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
228 ),
229 cast_to=str,
230 )
File ~\miniconda3\envs\openai_assistants_dev\Lib\site-packages\openai_base_client.py:998, in SyncAPIClient.get(self, path, cast_to, options, stream, stream_cls)
995 opts = FinalRequestOptions.construct(method=“get”, url=path, **options)
996 # cast is required because mypy complains about returning Any even though
997 # it understands the type variables
→ 998 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
File ~\miniconda3\envs\openai_assistants_dev\Lib\site-packages\openai_base_client.py:834, in SyncAPIClient.request(self, cast_to, options, remaining_retries, stream, stream_cls)
825 def request(
826 self,
827 cast_to: Type[ResponseT],
(…)
832 stream_cls: type[_StreamT] | None = None,
833 ) → ResponseT | _StreamT:
→ 834 return self._request(
835 cast_to=cast_to,
836 options=options,
837 stream=stream,
838 stream_cls=stream_cls,
839 remaining_retries=remaining_retries,
840 )
File ~\miniconda3\envs\openai_assistants_dev\Lib\site-packages\openai_base_client.py:877, in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
874 # If the response is streamed then we need to explicitly read the response
875 # to completion before attempting to access the response text.
876 err.response.read()
→ 877 raise self._make_status_error_from_response(err.response) from None
878 except httpx.TimeoutException as err:
879 if retries > 0:
BadRequestError: Error code: 400 - {‘error’: {‘message’: ‘Not allowed to download files of purpose: assistants’, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}
Anyone have this issue and can it be resolved?
Thanks!