I need to take the contents of a user's directory and send them in a request. Unfortunately I cannot modify the service i'm making the request to, and so I CANNOT zip all the files and send that, I must send all the files.
There's a limit on the total size of the files, but not on the # of files. Unfortunately once I try and open too many, Python will error out with: [Errno 24] Too many open files
. Here's my current code:
files_to_send = []
files_to_close = []
for file_path in all_files:
file_obj = open(file_path, "rb")
files_to_send.append(("files", (file_path, file_obj)))
files_to_close.append(file_obj)
requests.post(url, files=files_to_send)
for file_to_close in files_to_close:
file_to_close.close()
Is there any way to get around this open file limit given my circumstances?