i have the following code, and i want to know how can supress the error, i tried some google search but with no sucess.
def backup_system(dirs):
""" Funcao para fazer backup das confs do systema """
os.walk("/")
try:
tar = tarfile.open("/home/backup/system/system_backup_%s.tgz" % today, "w:gz")
for dir in system_dirs:
tar.add(dir,recursive=True)
finally:
tar.close()
print tar
ftp_put(tar)
def ftp_put(file):
"""Funcao para fazer upload dos arquivos para FTP"""
conn = ftplib.FTP(ftp_server, backup_user, backup_password)
f = open(file, 'r')
conn.storbinary("STOR ", f)
try:
f = open(file, 'r')
conn.storbinary("STOR ", f)
f.close()
finally:
conn.quit()
Well, it’s ok, except for the fact that this code returns error with the ftplib. It says that expect str, but found tarfile.
Many thanks.
Right, here is the error:
Traceback (most recent call last):
File "/usr/local/bin/backup.py", line 89, in <module>
main()
File "/usr/local/bin/backup.py", line 78, in main
backup_system(system_dirs)
File "/usr/local/bin/backup.py", line 42, in backup_system
ftp_put(tar)
File "/usr/local/bin/backup.py", line 55, in ftp_put
f = open(file, 'rb')
TypeError: coercing to Unicode: need string or buffer, TarFile found
To augment Ignacio’s answer I updated your backup_system a bit, hopefully this should do the trick.