读取文件时出现oserror无法加载外部实体

时间:2019-07-26 13:45:04

标签: python

我正在尝试使用XMLDiff-> Diff_Files属性来识别两个XML文件之间的差异。我遇到以下错误:

oserror错误,读取文件“ File1.xml”失败,无法加载外部实体“ File2.xml”

下面是我的代码:

def FileCompare (golden_path,golden_File,Output_path,Output_File):

    try:
        gold_file=golden_File
        Out_file = Output_File
        gold_path=golden_path +"\\"+golden_File 
        Out_path =Output_path +"\\"+Output_File

        print('Files being compared', gold_file, Out_file)
        result = main.diff_files(gold_file, Out_file, 
                                         formatter=formatting.XMLFormatter())
        print (result)

    except:
        print(traceback.format_exc())
        pass

我检查了文件的权限,但是具有完全访问权限。所以不确定为什么会给我这个错误。

1 个答案:

答案 0 :(得分:0)

欢迎来到stackoverflow。

根据错误消息,File1.xml包含文件File2.xml,并且无法读取。所以File2.xml要么丢失,要么在相对位置上,或者您是File1.xml所比较的文件,因此已经被锁定等。

相关问题