0
import csv
import simplekml
import codecs
def main():
   print("hello")
   print("hello again")
   kml=simplekml.Kml()
   with codecs.open('RMCQ1.csv','r',encoding='utf-8') as f:
       inputfile = csv.reader(f)
       inputfile.next()
       for row in inputfile:
           print("yes")
           pnt = kml.newpoint(name=row[1],coords=[(row[2],row[3],row[4])])
           print("yes gaain")
  kml.save('RMCQ1.kml')
if __name__ == '__main__':
  main()

I am trying to run the above code and I get this error:

hello
hello again

Traceback (most recent call last):
  File "/Users/nidhikantak/Desktop/kml/kmlconverter.py", line 18, in <module>
    main()
  File "/Users/nidhikantak/Desktop/kml/kmlconverter.py", line 11, in main
    inputfile.next()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 699, in next
    return self.reader.next()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 630, in next
    line = self.readline()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 545, in readline
    data = self.read(readsize, firstline=True)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/codecs.py", line 492, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xee in position 0: invalid continuation byte

How do I solve this error please?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
cuziluvtosmile
  • 47
  • 1
  • 1
  • 6
  • 2
    Don't use `codecs.open()` here; the Python 2 `csv.reader()` module can't deal with Unicode input anyway. See the duplicate on how to handle this porperly. You *may* still have issues with not having picked the right codec (i.e. the file is not actually UTF-8 encoded or has invalid data). – Martijn Pieters Apr 26 '17 at 13:17
  • 2
    Watch out for the byte order mark (BOM) at the beginning of the file. Try to open the fie with notepad++ it will tell you if it is encoded with BOM – Du D. Apr 26 '17 at 13:17
  • What do you mean by the duplicate to handle the unicode? – cuziluvtosmile Apr 26 '17 at 13:21
  • If there is no BOM at the beginning of file, should I add it? – cuziluvtosmile Apr 26 '17 at 13:23

0 Answers0