Unicode Error Printing Reportlab PDF Only While Running Not Debugging

3262
1
11-11-2014 12:54 AM
ShreyaChatterjee
New Contributor

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:

DOC.build(ELEMENTSOFDOC, onFirstPage=on_first_page, onLaterPages=on_later_pages, canvasmaker=NumberedCanvas)

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:

{u'Neighborhood Information': [u'Dominant Tapestry Segment:63', u'Labor Force Participation Rate:5,873', u'Total Population:17,045', u'Total Households:2,044', u'Average Household Size:3', u'Average Household Income:$58,312', u'Median Household Income:$26,260', u'Per Capita Income:$18,204', u'Total Housing Units:2,687', u'Owner Occupied HUs:400', u'Renter Occupied HUs:1,644', u'Vacant Housing Units:578', u'Median Home Value:$402,778', u'Average Home Value:$428,563'], u'Property Information': [u'Name:Rossborough Drive & Paint Branch Parkway', u'Address:Rossborough Drive & Paint Branch Parkway', u'City:College Park', u'State:MD', u'Zipcode:20742', u'Type:Commercial', u'Area (sqft):100000']}

Here's how I am building my attribute table dictionary:

TEMPDICT = {key : ATTRIBUTEDATA.find(key)} TABLEKEYSINDEX.update(TEMPDICT) SORTEDTABLESINDEX = sorted((value, key) for (key, value) in TABLEKEYSINDEX.items())

Here's how I am formatting the table:

table_key = (Paragraph(unicode((table_data[k][i].split(":"))[0], errors='ignore'), styles_table['TblBody']))  
if k == sorted_table_headers[0]: 
     if len((table_data[k][i].split(":"))[1]) != 0:
          value
= (Paragraph(unicode((table_data[k][i].split(":"))[1], errors='ignore'), styles_table['TblBody'])) 
else:
     if len((table_data[k][i].split(":"))[1]) !=0: 
          value
= (Paragraph(unicode((table_data[k][i].split(":"))[1], errors='ignore'), styles_table_right['TblBo                   dy']))

I have the following versions installed on my machine:

matplotlib (1.3.0) 
numpy
(1.7.1)
PIL
(1.1.7)
Pillow (2.5.2)
pip
(1.5.6)
pyparsing
(1.5.7)
reportlab
(3.1.8)
setuptools
(5.5.1)
ArcMap 10.2.1

Any help pointing me to the right direction would really be appreciated.

Tags (2)
0 Kudos
1 Reply
DrewDowling
Occasional Contributor III

Did you ever get a solution to this? I have a very similar problem. I'm using the python xhtml2pdf package (which uses reportlab I think) to export  metadata as a .pdf. Everything works fine as I debug or simple run the .py file from  IDLE but when I try to run it as part of a scheduled task I get:

'ascii' codec can't decode byte 0xa0 in position 6: ordinal not in range(128)

0 Kudos