Select to view content in your preferred language

UnicodeEncodeError

3822
3
05-27-2015 10:49 AM
CliveSwan
Frequent Contributor

I cannot retrieve records for a Arc/Oracle database

I get an "UnicodeEncodeError: 'ascii' codec can't encode character" error

snippet of the code:

sdeConn = arcpy.ArcSDESQLExecute(sde_conn_file)

for tbl in tableList:

    try:

        userValue = "u'"

        val = ''.join([x for x in userValue if ord(x) < 128])

       

        sdeReturn = sdeConn.execute("SELECT * FROM DBA_OBJECTS"  )

The records are printed out as:

[u'GISADMIN.KCC_KHS_CUSTOMER_LKP', u'GISADMIN.KCC_KHS_DISTRICT_LKP']

I tried to use a CSV.writer - did nothing??

def writerows(self, rows):

        file = open(output_file, 'wb')

        for row in rows:

            print row

            self.writerow(row)

            file.close()

I would appreciate assistance to get the CSV.writer working...

Thanks,

Clive

0 Kudos
3 Replies
CliveSwan
Frequent Contributor

I found a similar example @ arcpy.ArcSDESQLExecute(sde) problem

This has a working example of the CSV.Writer class.

Still getting an unicode error from the SQL statement:

sdeReturn = sdeConn.execute("SELECT * FROM DBA_OBJECTS"  )

0 Kudos
CliveSwan
Frequent Contributor

The script should return:

The code works on Database a

[u'USER, u'TABLE', u'Data1', u'Data2']

[u'USER, u'TABLE', u'Data1', u'Data2']

[u'USER, u'TABLE', u'Data1', u'Data2']

The u seems is needed for a new column, within the recordset.

The same script returns an error on Database b, an older database??

0 Kudos
HåvardMoe
Deactivated User

Which line of code is mentioned in the error message, and what's the full message? There should be a mention of the character in question there

0 Kudos