Select to view content in your preferred language

Export attachment error

1880
5
09-01-2016 03:53 AM
BartoszBrzeziński1
Regular Contributor

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.

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

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?

BartoszBrzeziński1
Regular Contributor

Yes, i`m using ArcMap 10.4.1

0 Kudos
DanPatterson_Retired
MVP Emeritus

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...

0 Kudos
BartoszBrzeziński1
Regular Contributor

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

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

0 Kudos
DanPatterson_Retired
MVP Emeritus

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'
0 Kudos