I have JSON data which I am formatting into two tables and printing on PDF using reportlab.
It works fine when the '&' character is not in the data else it gives The following error: 'ascii' codec can't decode byte 0xa0 in position 0: ordinal not in range(128)
The weird thing is, the code works perfectly fine while debugging the tool. The error only pops up while running the code here:
<SPAN class="pln" style="background: transparent;">DOC</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="pln" style="background: transparent;">build</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">ELEMENTSOFDOC</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> onFirstPage</SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;">on_first_page</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> onLaterPages</SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;">on_later_pages</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> canvasmaker</SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="typ" style="color: #2b91af; background: transparent;">NumberedCanvas</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN>
I have referred to the related questions posted. I have also tried the solution provided here and also normalizing the data. Nothing is working. It throws the same ascii error.
Here's the JSON input:
<SPAN class="pln" style="background: transparent;"></SPAN><SPAN class="pun" style="background: transparent;">{</SPAN><SPAN class="pln" style="background: transparent;">u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Neighborhood Information'</SPAN><SPAN class="pun" style="background: transparent;">:</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Dominant Tapestry Segment:63'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Labor Force Participation Rate:5,873'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Total Population:17,045'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Total Households:2,044'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Average Household Size:3'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Average Household Income:$58,312'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Median Household Income:$26,260'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Per Capita Income:$18,204'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Total Housing Units:2,687'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Owner Occupied HUs:400'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Renter Occupied HUs:1,644'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Vacant Housing Units:578'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Median Home Value:$402,778'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Average Home Value:$428,563'</SPAN><SPAN class="pun" style="background: transparent;">],</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Property Information'</SPAN><SPAN class="pun" style="background: transparent;">:</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Name:Rossborough Drive & Paint Branch Parkway'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Address:Rossborough Drive & Paint Branch Parkway'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'City:College Park'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'State:MD'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Zipcode:20742'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Type:Commercial'</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> u</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'Area (sqft):100000'</SPAN><SPAN class="pun" style="background: transparent;">]}</SPAN>Here's how I am building my attribute table dictionary:
<SPAN class="pln" style="background: transparent;">TEMPDICT </SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">{</SPAN><SPAN class="pln" style="background: transparent;">key </SPAN><SPAN class="pun" style="background: transparent;">:</SPAN><SPAN class="pln" style="background: transparent;"> ATTRIBUTEDATA</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="pln" style="background: transparent;">find</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">key</SPAN><SPAN class="pun" style="background: transparent;">)}</SPAN><SPAN class="pln" style="background: transparent;"> TABLEKEYSINDEX</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="pln" style="background: transparent;">update</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">TEMPDICT</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;"> SORTEDTABLESINDEX </SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;"> sorted</SPAN><SPAN class="pun" style="background: transparent;">((</SPAN><SPAN class="pln" style="background: transparent;">value</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> key</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="kwd" style="color: #00008b; background: transparent;">for</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">key</SPAN><SPAN class="pun" style="background: transparent;">,</SPAN><SPAN class="pln" style="background: transparent;"> value</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="kwd" style="color: #00008b; background: transparent;">in</SPAN><SPAN class="pln" style="background: transparent;"> TABLEKEYSINDEX</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="pln" style="background: transparent;">items</SPAN><SPAN class="pun" style="background: transparent;">())</SPAN>Here's how I am formatting the table:
<SPAN class="pln" style="background: transparent;">table_key </SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="typ" style="color: #2b91af; background: transparent;">Paragraph</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">unicode</SPAN><SPAN class="pun" style="background: transparent;">((</SPAN><SPAN class="pln" style="background: transparent;">table_data</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">k</SPAN><SPAN class="pun" style="background: transparent;">][</SPAN><SPAN class="pln" style="background: transparent;">i</SPAN><SPAN class="pun" style="background: transparent;">].</SPAN><SPAN class="pln" style="background: transparent;">split</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="str" style="color: #800000; background: transparent;">":"</SPAN><SPAN class="pun" style="background: transparent;">))[</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">0</SPAN><SPAN class="pun" style="background: transparent;">],</SPAN><SPAN class="pln" style="background: transparent;"> errors</SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'ignore'</SPAN><SPAN class="pun" style="background: transparent;">),</SPAN><SPAN class="pln" style="background: transparent;"> styles_table</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'TblBody'</SPAN><SPAN class="pun" style="background: transparent;">]))</SPAN><SPAN class="pln" style="background: transparent;">
</SPAN><SPAN class="kwd" style="color: #00008b; background: transparent;">if</SPAN><SPAN class="pln" style="background: transparent;"> k </SPAN><SPAN class="pun" style="background: transparent;">==</SPAN><SPAN class="pln" style="background: transparent;"> sorted_table_headers</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">0</SPAN><SPAN class="pun" style="background: transparent;">]:</SPAN><SPAN class="pln" style="background: transparent;">
</SPAN><SPAN class="kwd" style="color: #00008b; background: transparent;"> if</SPAN><SPAN class="pln" style="background: transparent;"> len</SPAN><SPAN class="pun" style="background: transparent;">((</SPAN><SPAN class="pln" style="background: transparent;">table_data</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">k</SPAN><SPAN class="pun" style="background: transparent;">][</SPAN><SPAN class="pln" style="background: transparent;">i</SPAN><SPAN class="pun" style="background: transparent;">].</SPAN><SPAN class="pln" style="background: transparent;">split</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="str" style="color: #800000; background: transparent;">":"</SPAN><SPAN class="pun" style="background: transparent;">))[</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN><SPAN class="pun" style="background: transparent;">])</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">!=</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="lit" style="color: #800000; background: transparent;">0</SPAN><SPAN class="pun" style="background: transparent;">:</SPAN><SPAN class="pln" style="background: transparent;">
value </SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="typ" style="color: #2b91af; background: transparent;">Paragraph</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">unicode</SPAN><SPAN class="pun" style="background: transparent;">((</SPAN><SPAN class="pln" style="background: transparent;">table_data</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">k</SPAN><SPAN class="pun" style="background: transparent;">][</SPAN><SPAN class="pln" style="background: transparent;">i</SPAN><SPAN class="pun" style="background: transparent;">].</SPAN><SPAN class="pln" style="background: transparent;">split</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="str" style="color: #800000; background: transparent;">":"</SPAN><SPAN class="pun" style="background: transparent;">))[</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN><SPAN class="pun" style="background: transparent;">],</SPAN><SPAN class="pln" style="background: transparent;"> errors</SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'ignore'</SPAN><SPAN class="pun" style="background: transparent;">),</SPAN><SPAN class="pln" style="background: transparent;"> styles_table</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'TblBody'</SPAN><SPAN class="pun" style="background: transparent;">]))</SPAN><SPAN class="pln" style="background: transparent;">
</SPAN><SPAN class="kwd" style="color: #00008b; background: transparent;">else</SPAN><SPAN class="pun" style="background: transparent;">:</SPAN><SPAN class="pln" style="background: transparent;">
</SPAN><SPAN class="kwd" style="color: #00008b; background: transparent;"> if</SPAN><SPAN class="pln" style="background: transparent;"> len</SPAN><SPAN class="pun" style="background: transparent;">((</SPAN><SPAN class="pln" style="background: transparent;">table_data</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">k</SPAN><SPAN class="pun" style="background: transparent;">][</SPAN><SPAN class="pln" style="background: transparent;">i</SPAN><SPAN class="pun" style="background: transparent;">].</SPAN><SPAN class="pln" style="background: transparent;">split</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="str" style="color: #800000; background: transparent;">":"</SPAN><SPAN class="pun" style="background: transparent;">))[</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN><SPAN class="pun" style="background: transparent;">])</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">!=</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">0</SPAN><SPAN class="pun" style="background: transparent;">:</SPAN><SPAN class="pln" style="background: transparent;">
value </SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="typ" style="color: #2b91af; background: transparent;">Paragraph</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="pln" style="background: transparent;">unicode</SPAN><SPAN class="pun" style="background: transparent;">((</SPAN><SPAN class="pln" style="background: transparent;">table_data</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="pln" style="background: transparent;">k</SPAN><SPAN class="pun" style="background: transparent;">][</SPAN><SPAN class="pln" style="background: transparent;">i</SPAN><SPAN class="pun" style="background: transparent;">].</SPAN><SPAN class="pln" style="background: transparent;">split</SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="str" style="color: #800000; background: transparent;">":"</SPAN><SPAN class="pun" style="background: transparent;">))[</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN><SPAN class="pun" style="background: transparent;">],</SPAN><SPAN class="pln" style="background: transparent;"> errors</SPAN><SPAN class="pun" style="background: transparent;">=</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'ignore'</SPAN><SPAN class="pun" style="background: transparent;">),</SPAN><SPAN class="pln" style="background: transparent;"> styles_table_right</SPAN><SPAN class="pun" style="background: transparent;">[</SPAN><SPAN class="str" style="color: #800000; background: transparent;">'TblBo dy'</SPAN><SPAN class="pun" style="background: transparent;">]))</SPAN>
I have the following versions installed on my machine:
<SPAN class="pln" style="background: transparent;">matplotlib </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1.3</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">0</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
numpy </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1.7</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
PIL </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1.1</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">7</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
</SPAN><SPAN class="typ" style="color: #2b91af; background: transparent;">Pillow</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">2.5</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">2</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
pip </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1.5</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">6</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
pyparsing </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1.5</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">7</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
reportlab </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">3.1</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">8</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
setuptools </SPAN><SPAN class="pun" style="background: transparent;">(</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">5.5</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN><SPAN class="pun" style="background: transparent;">)</SPAN><SPAN class="pln" style="background: transparent;">
</SPAN><SPAN class="typ" style="color: #2b91af; background: transparent;">ArcMap</SPAN><SPAN class="pln" style="background: transparent;"> </SPAN><SPAN class="lit" style="color: #800000; background: transparent;">10.2</SPAN><SPAN class="pun" style="background: transparent;">.</SPAN><SPAN class="lit" style="color: #800000; background: transparent;">1</SPAN>
Any help pointing me to the right direction would really be appreciated.