0
def upload(s):
     conn=tinys3.Connection("AKIAJPOZEBO47FJYS3OA","04IZL8X9wlzBB5LkLlZD5GI/",tls=True)
     f = open(s,'rb')
     z=str(datetime.datetime.now().date())
     x=z+'/'+s
     conn.upload(x,f,'crawling1')
     os.remove(s)   

The file is not deleting after i upload to s3 it is not deleting in the local directory any alternate solutions?

Jithin
  • 1,692
  • 17
  • 25

1 Answers1

0

You have to close the file before you can delete it:

import os

a = open('a')
os.remove('a')
>> Traceback (most recent call last):
   File "main.py", line 35, in <module>
      os.remove('a')
   PermissionError: [WinError 32] The process cannot access the file because 
   it is being used by another process: 'a'

You should add f.close() before the call to os.remove, or simply use with:

with open(s,'rb') as f:
    conn = tinys3.Connection("AKIAJPOZEBO47FJYS3OA","04IZL8X9wlzBB5LkLlZD5GI/",tls=True)
    z = str(datetime.datetime.now().date())
    x = z + '/' + s
    conn.upload(x, f, 'crawling1')
os.remove(s)
DeepSpace
  • 78,697
  • 11
  • 109
  • 154