Permissionerror: [Winerror 32] Another program is using this file, and the process cannot be accessed. Unable to delete files

tags: python  

if __name__ == '__main__':
    file_path = r'D:\\test/2022-04-20 01_16_00-SrCo311.xls'
         # Push file to the interface
    data = MultipartEncoder(fields={
        'propertyMessageXml': (os.path.basename(os.path.realpath(file_path)), open(file_path, 'rb'), 'text/xml')})
    res = requests.post(url=PUSH_URL, data=data,
                        headers={'Content-Type': data.content_type, 'Connection': 'close'})
         Print ("Push Result:", Res.Content.decode ('UTF8'))
    res.close()
    workbook = xlrd.open_workbook(file_path)
    sheet1 = workbook.sheets()[0]
         # Delete Files
    os.remove(file_path)

Question: After posting the file to the remote interface, open the excel file for classification and processing, and the excel file cannot be deleted.

Reason: Requests.post is not closed.

Solution: Make the entire post processTake it into a function, And in the functionActively turn off Request.

Practice method:

#  
def post_file(file_path):
    data = MultipartEncoder(fields={
        'propertyMessageXml': (os.path.basename(os.path.realpath(file_path)), open(file_path, 'rb'), 'text/xml')})
    r = requests.post(url=PUSH_URL, data=data,
                      headers={'Content-Type': data.content_type, 'Connection': 'close'})
         Print ("Push Result:", R.Content.decode ('UTF8'))
    r.close()


if __name__ == '__main__':
    file_path = r'D:\\test/2022-04-20 01_16_00-SrCo311.xls'
         # Push file to the interface
    post_file(file_path)
    workbook = xlrd.open_workbook(file_path)
    sheet1 = workbook.sheets()[0]
         # Delete Files 
    os.remove(file_path)

Intelligent Recommendation

Oldwood Take you --- Install the Python Package Permissionerror: [Winerror 32] Another program is using this file, the process is unacceptable.

When installing the python package with xgboost, the following error may occur: Because the terminal under Window is or the GBK encoding is displayed, the PIP source code is also modified. Open C: \ P...

python3.7: PermissionError: [WinError 32] The process cannot access the file because it is......

Problem Description: Python3.7, using the library image inside PIL just wants to get the length and wide of the picture Newspaper is wrong D:\Python37-32\python.exe D:/pyFile/python_script/img_read.py...

Java Process: Another program is using this file, the process cannot be accessed

When I recently dealt with strange problems, I made a low -level error, wasted a lot of time, and even watched the C code at the bottom of the JDK. The following test code is run by the Windows enviro...

Android Studio Another program is using this file process that cannot be accessed

I don't know which version begins, AS is always prompts the following errors, A simple solution: Switch toTerminal Window, direct inputgradlew -stop ,AgainbuildIt can be running normally....

Kafka in Windows Error: java.nio.file.filesystemXception: Another program is using this file, the process cannot access the process, the process cannot be accessed

Problem Description Kafka deployed in the Windows environment is hung after running for a period of time. View loglogs/server.log Discover the following errors: reason When the consumer's offset log i...

More Recommendation

IIS deployment local website prompts that the website cannot be started, another program is using this file, and the process cannot be accessed

Today, the website deployed with IIS cannot be started locally. The default port of https is 443. In order to avoid the port starting with 4 on the local computer, I tried to use port 555, and the pro...

Kafka 0.11x automatically stops after 30 seconds of startup, reported [another program is using this file, the process cannot be accessed]...

Environment: kafka_2.11-1.1.0, win7_64, java8 Phenomenon: automatically stops after 30 seconds of startup, reported [another program is using this file, the process cannot be accessed] It can be seen ...

Tips when compiling idea: another program is using this file, the process cannot be accessed; the problem is fixed

Regarding the idea when compiling idea: Another program is using this file and the process cannot be accessed. Problem repair record First report the original text: Error:Maven Resources Compiler: Fai...

Python Flask Logging Log Reports An error "Another program is using this file, the process cannot be accessed"

Article catalog Problem 2. Code example 3. Reason 4. Solve Problem Python Flask Logging Log Reports An error "Another program is using this file, the process cannot be accessed" 2. Code exam...

[Error Record] Flutter mixed development error (java.nio.file.filesystemException: xxx / r.jar: Another program is using this file, the process cannot be accessed.)

Article catalog First, error information Second, the solution First, error information FLUTTER Mixed Development Project: In the Android project, embed the flutter page, accidentally run the Flutter p...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top