I'm trying to export all attachments from an attachment table in a gdb to a folder. I'm using a script I found here. I keep getting the error that item[0] is None and so has no attribute 'tobytes'. This table is a standard ATTACH table with the default fields. I appreciate any suggestions!
inTable = [path to ATTACH table] fileLocation = [Export folder]
for fc in list: print(fc)
with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor: for item in cursor: attachment = item[0] print(attachment) filenum = str(item[2]) + "_" print(filenum) filename = filenum + str(item[1]) print(filename) open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes()) del item del filenum del filename del attachment
Traceback (most recent call last): File "C:\Users\gscmm\PycharmProjects\pythonProject2\AttachmentDownloader.py", line 33, in open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes()) AttributeError: 'NoneType' object has no attribute 'tobytes'