<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: ArcSDESQLExecute error message contains unicode character in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67603#M5537</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting, or oddly, IDLE on my 10.3 machine handles it fine.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="arcpy_arcsdesqlexecute_print_error.PNG" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/55267_arcpy_arcsdesqlexecute_print_error.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;I am still convinced the extra error message is tied to the console where the original error message is trying to be printed.&amp;nbsp; That said, I can't imagine a bit change in IDLE or Python between 10.2.2 and 10.3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you point out, you already know how to work around the issue, which is really the most important thing.&amp;nbsp; In terms of Unicode characters, it would be interesting to know why the ArcSDE errors are getting returned with a problematic character on the end.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 28 Jan 2015 02:28:51 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2015-01-28T02:28:51Z</dc:date>
    <item>
      <title>ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67596#M5530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you execute an invalid SQL statement with arcpy.ArcSDESQLExecute(), it will return an error message with a unicode special character (see ArcSDESQLExecute_Error.gif). That unicode character in the error message actually causes an error with Python if you try to print the message (see PythonUnicode_Error.gif). Apparently this is a &lt;A href="http://bugs.python.org/issue2517" rel="nofollow noopener noreferrer" target="_blank"&gt;known Python issue&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found you have to wrap the arcpy error message up in encoding so Python doesn't choke (haha).&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;except Exception as err:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise Exception(unicode(err.message).encode("utf-8"))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why is this silly unicode character in an error message anyway? Has anyone else found a better way to deal with this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:36:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67596#M5530</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-10T22:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67597#M5531</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What version of ArcGIS and Python are you using?&amp;nbsp; The known Python issue you reference affected Python 2.5 and 2.6, which the last version to ship with one of those versions was ArcGIS 10.0.&amp;nbsp; I am able to print the error message without encoding changes and no crashes in ArcGIS 10.3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, it is odd that the error message returns an invalid Unicode character.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 04:26:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67597#M5531</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-27T04:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67598#M5532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm using PyScripter for Python 2.7 with ArcGIS 10.2.2 (which I believe ships with Python 2.7.5).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 15:24:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67598#M5532</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-01-27T15:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67599#M5533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure why you are getting an error when you print the Unicode with the invalid character.&amp;nbsp; Understanding there is an invalid character, printing the string from Python 2.7 shouldn't cause an error since the bug was fixed.&amp;nbsp; That said, it would be nice if Esri's error handling was cleaner.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 15:32:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67599#M5533</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-27T15:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67600#M5534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://pythonhosted.org/kitchen/unicode-frustrations.html#frustration-5-exceptions"&gt;This Python document&lt;/A&gt; mentions the issue of printing Exceptions with unicode characters but it's just generically directed at Python 2.x&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 15:40:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67600#M5534</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-01-27T15:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67601#M5535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The issue you are experiencing is likely due to your console the error messages are being printed to and not Python itself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I run similar code in the interactive Python windows in ArcMap, it prints fine.&amp;nbsp; If I run the code in PyCharm, it prints fine.&amp;nbsp; If I run the code from a Windows command prompt, it generates a similar error you are seeing.&amp;nbsp; My guess is that the PyScripter console is not coping with the Unicode and hence the extra error is being generated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 23:40:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67601#M5535</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-27T23:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67602#M5536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may be right, possibly something with my version of Python and the place I'm running it from. I'm not sure how to run it from Windows Command Prompt so I just tried it in IDLE and still get the same error. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/confused.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's how I'm running it&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sdeconn = r"C:\GISConnections\SDE@GTEST.sde"
&amp;nbsp;&amp;nbsp;&amp;nbsp; sql = "SELECT * FROM INVALID_TABLE"
&amp;nbsp;&amp;nbsp;&amp;nbsp; cnxn = arcpy.ArcSDESQLExecute(sdeconn)
&amp;nbsp;&amp;nbsp;&amp;nbsp; sqlresult = cnxn.execute(sql)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in sqlresult:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print i
except Exception as err:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print unicode(err.message).encode("utf-8")&amp;nbsp; ## Successfully prints Esri error message
&amp;nbsp;&amp;nbsp;&amp;nbsp; print err&amp;nbsp; ## Throws Python error
finally:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Cleanup
&amp;nbsp;&amp;nbsp;&amp;nbsp; if 'cnxn' in locals():
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del cnxn&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your persistence, Joshua. At least I know how to handle the error for now. I'll just hope it will go away after the next ArcGIS upgrade we do.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:36:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67602#M5536</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-10T22:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: ArcSDESQLExecute error message contains unicode character</title>
      <link>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67603#M5537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting, or oddly, IDLE on my 10.3 machine handles it fine.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="arcpy_arcsdesqlexecute_print_error.PNG" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/55267_arcpy_arcsdesqlexecute_print_error.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;I am still convinced the extra error message is tied to the console where the original error message is trying to be printed.&amp;nbsp; That said, I can't imagine a bit change in IDLE or Python between 10.2.2 and 10.3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you point out, you already know how to work around the issue, which is really the most important thing.&amp;nbsp; In terms of Unicode characters, it would be interesting to know why the ArcSDE errors are getting returned with a problematic character on the end.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jan 2015 02:28:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcsdesqlexecute-error-message-contains-unicode/m-p/67603#M5537</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2015-01-28T02:28:51Z</dc:date>
    </item>
  </channel>
</rss>

