Note that there are some explanatory texts on larger screens.

plurals
  1. PO'ascii' codec can't decode byte 0xef in position
    text
    copied!<p>I am getting this pesky error on this line:</p> <pre><code> r += '\n&lt;Placemark&gt;&lt;name&gt;'+row[3].encode('utf-8','xmlcharrefreplace')+'&lt;/name&gt;' \ '\n&lt;description&gt;'+desc.encode('utf-8','xmlcharrefreplace')+'&lt;/description&gt;\n' \ '&lt;Point&gt;&lt;coordinates&gt;'+row[clat].encode('utf-8','xmlcharrefreplace')+ ','+row[clongitude].encode('utf-8','xmlcharrefreplace')+'&lt;/coordinates&gt;&lt;/Point&gt;\n' \ '&lt;address&gt;'+row[4].encode('utf-8','xmlcharrefreplace')+'&lt;/address&gt;\n' \ '&lt;styleUrl&gt;'+row[cstyleID].encode('utf-8','xmlcharrefreplace')+'&lt;/styleUrl&gt;\n' \ '&lt;/Placemark&gt;' </code></pre> <p>here is the error:</p> <pre><code>Traceback (most recent call last): File "&lt;pyshell#38&gt;", line 1, in &lt;module&gt; doStuff() File "C:\Python27\work\GenerateKML.py", line 5, in doStuff createFiles('together.csv') File "C:\Python27\work\GenerateKML.py", line 55, in createFiles '&lt;styleUrl&gt;'+row[cstyleID].encode('utf-8','xmlcharrefreplace')+'&lt;/styleUrl&gt;\n' \ UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 60: ordinal not in range(128) </code></pre> <p>What am I doing wrong?</p> <p>thank you for your help.</p> <p>here's the full source:</p> <pre><code>import hashlib import csv def doStuff(): createFiles('together.csv') def readFile(fileName): a=open(fileName) fileContents=a.read() a.close() return fileContents def readCSVFile(fileName): return list(csv.reader(open(fileName, 'rb'), delimiter=',', quotechar='"')) def GetDistinctValues(theFile, theColumn): with open(theFile, "rb") as fp: reader = csv.reader(fp) return list(set(line[theColumn] for line in reader)) def createFiles(inputFile): cNAME=3 clat=0 clongitude=1 caddress1=4 caddress2=5 cplace=6 ccity=7 cstate=8 czip=9 cphone=10 cwebsite=11 cstyleID=18 inputFileText=readCSVFile(inputFile) headerFile = readFile('header.txt') footerFile = readFile('footer.txt') r=headerFile DISTINCTCOLUMN=12 dValues = GetDistinctValues(inputFile,DISTINCTCOLUMN) counter=0 for uniqueValue in dValues: counter+=1 print uniqueValue theHash=hashlib.sha224(uniqueValue).hexdigest() for row in inputFileText: if uniqueValue==row[DISTINCTCOLUMN]: for eachElement in row: eachElement=eachElement.replace('&amp;','&amp;amp;') desc = ' '.join(row[3:]) r += '\n&lt;Placemark&gt;&lt;name&gt;'+row[3].encode('utf-8','xmlcharrefreplace')+'&lt;/name&gt;' \ '\n&lt;description&gt;'+desc.encode('utf-8','xmlcharrefreplace')+'&lt;/description&gt;\n' \ '&lt;Point&gt;&lt;coordinates&gt;'+row[clat].encode('utf-8','xmlcharrefreplace')+ ','+row[clongitude].encode('utf-8','xmlcharrefreplace')+'&lt;/coordinates&gt;&lt;/Point&gt;\n' \ '&lt;address&gt;'+row[4].encode('utf-8','xmlcharrefreplace')+'&lt;/address&gt;\n' \ '&lt;styleUrl&gt;'+row[cstyleID].encode('utf-8','xmlcharrefreplace')+'&lt;/styleUrl&gt;\n' \ '&lt;/Placemark&gt;' r += footerFile f = open(theHash+'.kml','w') f.write(r) f.close() r=headerFile </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload