Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: I/O operation on closed file #125

Open
fujiawei0724 opened this issue Mar 20, 2024 · 3 comments
Open

ValueError: I/O operation on closed file #125

fujiawei0724 opened this issue Mar 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@fujiawei0724
Copy link

When I want to upload an image from local path, that error exists

code:
client = PoeApi(cookie=tokens) bot = "claude_2_1_bamboo" local_paths = ["/research/d1/rshr/jwfu/tmp/1661501360757.0_left.jpg"] for chunk in client.send_message(bot, "What is this file about?", file_path=local_paths): print(chunk["response"], end="", flush=True)

error:
Traceback (most recent call last): File "test_poe_api.py", line 38, in <module> for chunk in client.send_message(bot, "What is this file about?", file_path=local_paths): File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/poe_api_wrapper/api.py", line 843, in send_message raise e File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/poe_api_wrapper/api.py", line 810, in send_message message_data = self.send_request(apiPath, 'SendMessageMutation', variables, file_form) File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/poe_api_wrapper/api.py", line 222, in send_request payload = MultipartEncoder( File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 125, in __init__ self._prepare_parts() File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in _prepare_parts self.parts = [Part.from_field(f, enc) for f in self._iter_fields()] File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 246, in <listcomp> self.parts = [Part.from_field(f, enc) for f in self._iter_fields()] File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 495, in from_field return cls(headers, body) File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 488, in __init__ self.len = len(self.headers) + total_len(self.body) File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 432, in total_len if hasattr(o, 'len'): File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 573, in len return total_len(self.fd) - self.fd.tell() File "/research/d1/rshr/jwfu/anaconda3/envs/tmp/lib/python3.8/site-packages/requests_toolbelt/multipart/encoder.py", line 437, in total_len fileno = o.fileno() ValueError: I/O operation on closed file

Thanks for your help

@YogeLiu
Copy link

YogeLiu commented Mar 20, 2024

the file has closed after post request int the functionsend_request, then the send_message will call send_requestagain. Close the same file loads to occur a exception.

@snowby666 snowby666 added the bug Something isn't working label Mar 20, 2024
@theblackrussian
Copy link

I confirm that this problem occurred after updating to 1.4.0
I have the exact same codebase on 2 different laptops and after updating poe-api-wrapper from 1.3.7 to 1.4.0, this error started to appear.
As mentioned by OP, it occurs when uploading a file.
It still works on version 1.3.7, so I assume its not caused by their API or any change made in the back-end.

@joker10201023
Copy link

In my usage scenario, setting msgPrice=*correct msgPrice* can solve this problem.
This is because when it is detected that msgPrice does not match the actual situation, send_request will be sent again.
I guess that after the first send, the file is closed; so simply directly set the correct msgPrice.
Since I have other more urgent things right now, I don't have time to fix this problem; if I have time in the future, I will dig in and fix this problem. If anyone else is interested in this problem, you can try reading this Code snippet if message_data["data"] != .....
By the way, sorry for my bad English.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants