Export attachment error

1086
5
09-01-2016 03:53 AM
Highlighted
New Contributor III

Hi, 

I`m using this script to export attachments from my geodatabase:

import arcpy
from arcpy import da
import os

inTable = arcpy.GetParameterAsText (0)
fileLocation = arcpy.GetParameterAsText (1)

with da.SearchCursor(inTable, ['DATA', 'ATT_NAME', 'ATTACHMENTID']) as cursor:

for item in cursor:

attachment = item[0]
filenum = str(item [2]) + "_"
filename = str(item[1])
open(fileLocation + os.sep + filename, 'wb').write(attachment.tobytes())
del item
del filenum
del filename
del attachment

During procedure i get this warning:

 Do you have idea what is wrong? Thanks for help.

Reply
0 Kudos
5 Replies
Highlighted
MVP Esteemed Contributor

yes... your folder D:\07_....

Copy and paste as text the actual folder name.

Always use raw encoding  especially if you have a different internationalization.  ie r"D:\MyStuff"

This line at the very top of your scripts goes a long way to fixing some issues

# -*- coding: UTF-8 -*-

I assume python 2.7? and ArcMap?

Highlighted
New Contributor III

Yes, i`m using ArcMap 10.4.1

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

So what is the path??? it is not being interpreted properly and that suggests an issue with the characters in the folder path, which may be internationalization issues or the path strings are being interpreted wrong. 

Have a look at this...

Reply
0 Kudos
Highlighted
New Contributor III

C:\Users\BBrzezinski\Desktop\Export.py - path of script;

D:\07_PRACE_GIS\Phyton_Toolbox\Toolbox.tbx - path of toolbox

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

you need raw formatting... and beginning a path with a space is not good practice for obvious reasons

p = "D:\07_PRACE_GIS\Phyton_Toolbox\Toolbox.tbx"

p
Out[2]: 'D:\x07_PRACE_GIS\\Phyton_Toolbox\\Toolbox.tbx'

p = r"D:\07_PRACE_GIS\Phyton_Toolbox\Toolbox.tbx"

p
Out[4]: 'D:\\07_PRACE_GIS\\Phyton_Toolbox\\Toolbox.tbx'
Reply
0 Kudos