cleder / fastkml

Fast 🌍️ KML processing for python
https://fastkml.readthedocs.io
217 stars 90 forks source link

Value Error on running Example scripts. #144

Closed withoutwaxaryan closed 2 years ago

withoutwaxaryan commented 2 years ago

When you try to run examples/ReadKml.py & examples/UsageExamples.py, the following error arises :

Traceback (most recent call last):
  File "UsageExamples.py", line 22, in <module>
    k.from_string(kmlFile.read())
  File "/home/aryan/anaconda3/lib/python3.7/site-packages/fastkml/kml.py", line 90, in from_string
    xml_string, parser=etree.XMLParser(huge_tree=True, recover=True)
  File "src/lxml/etree.pyx", line 3237, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1891, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
martimpassos commented 2 years ago

Hi, is the fix up on PyPi already? I'm getting the same error with

with open("/content/001AAN005121.kml", 'rt', encoding="utf-8") as myfile:
  doc=myfile.read()
  k.from_string(doc)

Changing it to

with open("/content/001AAN005121.kml", 'rt', encoding="utf-8") as myfile:
  doc=myfile.read()
  k.from_string(bytes(doc))

Gives TypeError: string argument without an encoding

withoutwaxaryan commented 2 years ago

Hi,

Can you check if the changes in the linked PR works for you?

martimpassos commented 2 years ago

Yes I have done that and it works well, thanks!