<?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 Unicode Errors in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unicode-errors/m-p/25619#M1935</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;More than once I've come across unicode errors when using a da cursor (see&amp;nbsp;&lt;A href="https://community.esri.com/thread/228759" target="_blank"&gt;'ascii' codec can't encode character u'\u201c' &lt;/A&gt;&amp;nbsp;) or some other type of field value manipulation ( &lt;A href="https://community.esri.com/thread/228309" target="_blank"&gt;Where clause for '\n'&lt;/A&gt;&amp;nbsp;).&amp;nbsp; My latest adventure into these errors is using python to execute a sql query through pyodbc, writing the results to a csv file.&amp;nbsp; The end game to this is to get the data out of the SQL server db and into a fgdb.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Life is all about trade-offs.&amp;nbsp; I prefer to use the python-odbc-to-csv approach as it preserves date-type fields even when the fields have null or no values in them. But, the trade off is you can run into unicode errors like this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;UnicodeEncodeError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'charmap'&lt;/SPAN&gt; codec can&lt;SPAN class="string token"&gt;'t encode character '&lt;/SPAN&gt;\ufffd' &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; position &lt;SPAN class="number token"&gt;226&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; character maps to &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;undefined&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another tactic is to use Sql Server Management Studio (SSMS) to execute the query and then export the results to a csv; the trade off with this approach is date fields with null or empty values get automagically converted into text fields, rendering useless for date range queries.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Admittedly, I'm not the sharpest knife in the drawer when it comes to codecs and related issues, but I wanted to see if I could figure out a way past the unicode errors, and keep the date fields intact. In my googling I stumbled upon a couple of resources:&amp;nbsp;&lt;A class="link-titled" href="https://pymotw.com/2/codecs/" title="https://pymotw.com/2/codecs/" rel="nofollow noopener noreferrer" target="_blank"&gt;codecs – String encoding and decoding - Python Module of the Week&lt;/A&gt;&amp;nbsp; and&amp;nbsp;&lt;A class="link-titled" href="https://docs.python.org/3/howto/unicode.html" title="https://docs.python.org/3/howto/unicode.html" rel="nofollow noopener noreferrer" target="_blank"&gt;Unicode HOWTO — Python 3.8.4rc1 documentation&lt;/A&gt;&amp;nbsp; which have helped put a little better edge on my otherwise dull blade.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code I'm working with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; pyodbc &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; odbc
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; csv&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; os


conn &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; odbc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;connect&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Driver={SQL Server};'&lt;/SPAN&gt;
                    &lt;SPAN class="string token"&gt;'Server=xxxxx;'&lt;/SPAN&gt;
                    &lt;SPAN class="string token"&gt;'Database=HANSEN;'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

outFolder &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\Hansen'&lt;/SPAN&gt;                    

query &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"""select * 
            from imsv7.APCASE
            """&lt;/SPAN&gt;

cursor &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; conn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;cursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;execute&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;query&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fetchall&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
column_names &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;description&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
dotcsv &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'APCASE_py.csv'&lt;/SPAN&gt;
outFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;outFolder&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;dotcsv&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;newline &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
myFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; csv&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;outFile&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
myFile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writerow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;column_names&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
myFile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writerows&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rows&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Focus your attention on line 21. By making a slight adjustment I have been able to overcome the error shown above:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;outFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;outFolder&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;dotcsv&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;newline &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;encoding &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'utf-16'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The addition of&amp;nbsp;encoding = 'utf-16' is apparently all it takes.&amp;nbsp; And, as with life's trade offs, opinions are a dime a dozen and even cheaper now with internet forums:&amp;nbsp;&lt;A class="link-titled" href="https://www.quora.com/What-are-reasons-to-use-UTF-16-instead-of-UTF-8-in-some-situations" title="https://www.quora.com/What-are-reasons-to-use-UTF-16-instead-of-UTF-8-in-some-situations" rel="nofollow noopener noreferrer" target="_blank"&gt;What are reasons to use UTF-16 instead of UTF-8 in some situations? - Quora&lt;/A&gt;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The bottom line for me is I am able to get past the error, maintain my date fields and get the results I'm after.&amp;nbsp; In the future, I'll probably use the encoding = 'utf-16' as my default, to avoid any errors.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 21:02:20 GMT</pubDate>
    <dc:creator>JoeBorgione</dc:creator>
    <dc:date>2021-12-10T21:02:20Z</dc:date>
    <item>
      <title>Unicode Errors</title>
      <link>https://community.esri.com/t5/python-questions/unicode-errors/m-p/25619#M1935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;More than once I've come across unicode errors when using a da cursor (see&amp;nbsp;&lt;A href="https://community.esri.com/thread/228759" target="_blank"&gt;'ascii' codec can't encode character u'\u201c' &lt;/A&gt;&amp;nbsp;) or some other type of field value manipulation ( &lt;A href="https://community.esri.com/thread/228309" target="_blank"&gt;Where clause for '\n'&lt;/A&gt;&amp;nbsp;).&amp;nbsp; My latest adventure into these errors is using python to execute a sql query through pyodbc, writing the results to a csv file.&amp;nbsp; The end game to this is to get the data out of the SQL server db and into a fgdb.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Life is all about trade-offs.&amp;nbsp; I prefer to use the python-odbc-to-csv approach as it preserves date-type fields even when the fields have null or no values in them. But, the trade off is you can run into unicode errors like this one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;UnicodeEncodeError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'charmap'&lt;/SPAN&gt; codec can&lt;SPAN class="string token"&gt;'t encode character '&lt;/SPAN&gt;\ufffd' &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; position &lt;SPAN class="number token"&gt;226&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; character maps to &lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt;undefined&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another tactic is to use Sql Server Management Studio (SSMS) to execute the query and then export the results to a csv; the trade off with this approach is date fields with null or empty values get automagically converted into text fields, rendering useless for date range queries.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Admittedly, I'm not the sharpest knife in the drawer when it comes to codecs and related issues, but I wanted to see if I could figure out a way past the unicode errors, and keep the date fields intact. In my googling I stumbled upon a couple of resources:&amp;nbsp;&lt;A class="link-titled" href="https://pymotw.com/2/codecs/" title="https://pymotw.com/2/codecs/" rel="nofollow noopener noreferrer" target="_blank"&gt;codecs – String encoding and decoding - Python Module of the Week&lt;/A&gt;&amp;nbsp; and&amp;nbsp;&lt;A class="link-titled" href="https://docs.python.org/3/howto/unicode.html" title="https://docs.python.org/3/howto/unicode.html" rel="nofollow noopener noreferrer" target="_blank"&gt;Unicode HOWTO — Python 3.8.4rc1 documentation&lt;/A&gt;&amp;nbsp; which have helped put a little better edge on my otherwise dull blade.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the code I'm working with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; pyodbc &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; odbc
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; csv&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; os


conn &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; odbc&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;connect&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'Driver={SQL Server};'&lt;/SPAN&gt;
                    &lt;SPAN class="string token"&gt;'Server=xxxxx;'&lt;/SPAN&gt;
                    &lt;SPAN class="string token"&gt;'Database=HANSEN;'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

outFolder &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; r&lt;SPAN class="string token"&gt;'C:\Hansen'&lt;/SPAN&gt;                    

query &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"""select * 
            from imsv7.APCASE
            """&lt;/SPAN&gt;

cursor &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; conn&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;cursor&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;execute&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;query&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

rows &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fetchall&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
column_names &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;description&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
dotcsv &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'APCASE_py.csv'&lt;/SPAN&gt;
outFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;outFolder&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;dotcsv&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;newline &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
myFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; csv&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writer&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;outFile&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
myFile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writerow&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;column_names&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
myFile&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;writerows&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;rows&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

cursor&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;close&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Focus your attention on line 21. By making a slight adjustment I have been able to overcome the error shown above:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;outFile &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; open&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;os&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;path&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;outFolder&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;dotcsv&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'w'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;newline &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;encoding &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'utf-16'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The addition of&amp;nbsp;encoding = 'utf-16' is apparently all it takes.&amp;nbsp; And, as with life's trade offs, opinions are a dime a dozen and even cheaper now with internet forums:&amp;nbsp;&lt;A class="link-titled" href="https://www.quora.com/What-are-reasons-to-use-UTF-16-instead-of-UTF-8-in-some-situations" title="https://www.quora.com/What-are-reasons-to-use-UTF-16-instead-of-UTF-8-in-some-situations" rel="nofollow noopener noreferrer" target="_blank"&gt;What are reasons to use UTF-16 instead of UTF-8 in some situations? - Quora&lt;/A&gt;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The bottom line for me is I am able to get past the error, maintain my date fields and get the results I'm after.&amp;nbsp; In the future, I'll probably use the encoding = 'utf-16' as my default, to avoid any errors.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:02:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unicode-errors/m-p/25619#M1935</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-12-10T21:02:20Z</dc:date>
    </item>
  </channel>
</rss>

