JavaScript
x
2
1
files = {'file': ('output.mp3', open('output.mp3','rb'), 'audio/mpeg')}
2
I am using this for POST request but after usage trying to delete it with os.remove and it gives “it’s used by a process”. How to close file after?
Advertisement
Answer
You can use with ...
:
JavaScript
1
12
12
1
import os
2
import requests
3
4
# open the file and send it
5
with open("output.mp3", "rb") as my_file:
6
files = {"file": ("output.mp3", my_file, "audio/mpeg")}
7
r = requests.post(url, files=files)
8
# ...
9
10
# file is closed now, remove it
11
os.remove("output.mp3")
12