I got an SystemError : error return without exception set error when trying to write a unicode into a blob field into a table inside a FGDB using arcpy.da.UpdateCursor with ArcGIS v10.3
for instance:
import arcpy
value = u"a unicode string! with some accent éàèû"
with arcpy.da.UpdateCursor(r"c:\\my_fgdb.fgdb\my_table", ["blob_field"], where_clause="FID = '0') as cursor:
for row in cursor:
row[0] = value
cursor.updateRow(row)
I know blob can store string, but is it normal it cannot store unicode?
Solved! Go to Solution.
Since ArcGIS Desktop/ArcMap uses Python 2.x, inserting or updating a Blob field with a Python str object works because str is a sequence of bytes. A Unicode string is a sequence of Unicode code points, not bytes. Since a Blob field is designed to store binary data, you can't directly insert or update a Blob field with a Python Unicode string. If you want to work with Unicode strings in Blob fields, you will need to encode and decode the strings first.
import arcpy
value = u"a unicode string! with some accent éàèû"
with arcpy.da.UpdateCursor(r"c:\\my_fgdb.fgdb\my_table", ["blob_field"], where_clause="FID = '0') as cursor:
for row in cursor:
row[0] = value.encode('utf8')
cursor.updateRow(row)
Since ArcGIS Desktop/ArcMap uses Python 2.x, inserting or updating a Blob field with a Python str object works because str is a sequence of bytes. A Unicode string is a sequence of Unicode code points, not bytes. Since a Blob field is designed to store binary data, you can't directly insert or update a Blob field with a Python Unicode string. If you want to work with Unicode strings in Blob fields, you will need to encode and decode the strings first.
import arcpy
value = u"a unicode string! with some accent éàèû"
with arcpy.da.UpdateCursor(r"c:\\my_fgdb.fgdb\my_table", ["blob_field"], where_clause="FID = '0') as cursor:
for row in cursor:
row[0] = value.encode('utf8')
cursor.updateRow(row)
Hello Joshua,
Thank you for the information about the blob field!
Do you have an idea why storing unicode in text field works?
The ArcGIS Text field is actually Unicode: ArcGIS field data types—ArcGIS Help | ArcGIS Desktop
The characters used for text vary by language. To allow text to more easily convert between languages, ArcGIS uses Unicode to encode characters.