使用ldif3模块的LDIFParser读取ldif文件,但一直会有如下报错:
from ldif3 import LDIFParser
dn_attr_dict = {}
parser = LDIFParser(open('adam.ldif', 'rb'))
# parser = LDIFParser(open('correctadam.ldif', 'rb'))
for dn, entry in parser.parse():
try:
dn_attr_dict[dn] = entry
except:
print("error")
print(dn_attr_dict)
报错输出
Traceback (most recent call last):
File "C:\Users\useful_tools\htd.py", line 20, in <module>
for dn, entry in parser.parse():
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\ldif.py", line 253, in parse
yield self._parse_entry_record(block)
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\ldif.py", line 365, in _parse_entry_record
attr_type, attr_value = self._parse_attr(line)
File "C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\ldif.py", line 318, in _parse_attr
colon_pos = line.index(b":")
ValueError: subsection not found
读取correctadam.ldif可以正常输出内容,但读取adam.ldif则会报错,对比了这两个文件的大小,前者比后者小很多。请问大家该如何修复这个问题?