2016-06-28 10 views
-5

は、私は同じエラーを取得し続ける:私のpythonスクリプトが動作しないのはなぜですか?

File "backup.py", line 26
logging.error("Unable to create backup.zip")
IndentationError: unindent does not match any outer indentation level

これは私のスクリプトです:

import sys 
import os 
import logging 

logging.basicConfig(filename='file_ex.log', level = logging.DEBUG) 

logging.info("checking to see if the backup.zip exists") 

if os.path.exists("backup.zip"): 
    logging.info("It exists!") 
try: 
    zip_file = zipfile.ZipFile('backup.zip','a') 
except: 
    err = sys.exc_info() 
    logging.error("Unable to open backup.zip in append mode") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " = err[1].args[1]) 
    sys.exit() 

else: 
    logging.info("Creating backup.zip") 
try: 
    zip_file = zipfile.ZipFile('backup.zip', 'w') 
except: 
    err = sys.exc_info() 
    logging.error("Unable to create backup.zip") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " + err[1].args[1]) 
    sys.exit() 

else: 
    logging.info("Creating backup.zip") 
try: 
    zip_file = zipfile.ZipFile('backup.zip', 'w') 
except: 
    err = sys.exc_info() 
    logging.error("Unable to create backup.zip") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " + err[1].args[1]) 
    logging.info("adding test.txt to backup.zip") 

try: 
    zip_file.write('test.txt', 'test.txt', zipfile.ZIP_DEFLATED) 
except: 
    err = sys.exc_info() 
    logging.error("Unable to open backup.zip in append mode") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " = err[1].args[1]) 
    zip_file.close() 
+0

あなたのインデントはイコール 'logging.errorでサインインして何、ところで – Aidan

+0

間違っています( "エラーメッセージ:"= ERR [1] .args [1])'? –

答えて

0

あなたのインデントを修正してみてくださいライン17及び48 logging.error("Error Msg: " = err[1].args[1])

0

のエラーを持っています。

あなたの例では、try except文がどこに属しているかを正確に見るのは難しいですが、あなたがしようとしていると思われるものに基づいて正しい字下げになると思われるコードスニペットを行っています。

import sys 
import os 
import logging 

logging.basicConfig(filename='file_ex.log', level = logging.DEBUG) 

logging.info("checking to see if the backup.zip exists") 

if os.path.exists("backup.zip"): 
    logging.info("It exists!") 
    try: 
    zip_file = zipfile.ZipFile('backup.zip','a') 
    except: 
    err = sys.exc_info() 
    logging.error("Unable to open backup.zip in append mode") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " = err[1].args[1]) 
    sys.exit() 
else: 
    logging.info("Creating backup.zip") 
    try: 
    zip_file = zipfile.ZipFile('backup.zip', 'w') 
    except: 
    err = sys.exc_info() 
    logging.error("Unable to create backup.zip") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " + err[1].args[1]) 
    sys.exit() 
    else: 
    logging.info("Creating backup.zip") 
    try: 
    zip_file = zipfile.ZipFile('backup.zip', 'w') 
    except: 
     err = sys.exc_info() 
     logging.error("Unable to create backup.zip") 
     logging.error("Error Num: " + str(err[1].args[0])) 
     logging.error("Error Msg: " + err[1].args[1]) 
     logging.info("adding test.txt to backup.zip") 
try: 
    zip_file.write('test.txt', 'test.txt', zipfile.ZIP_DEFLATED) 
except: 
    err = sys.exc_info() 
    logging.error("Unable to open backup.zip in append mode") 
    logging.error("Error Num: " + str(err[1].args[0])) 
    logging.error("Error Msg: " = err[1].args[1]) 
    zip_file.close() 
関連する問題