Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused with PyQuery() #251

Open
ninsiu-com opened this issue Jul 22, 2023 · 1 comment
Open

Confused with PyQuery() #251

ninsiu-com opened this issue Jul 22, 2023 · 1 comment

Comments

@ninsiu-com
Copy link

Hi:

I'm using PyQuery to extract information from xml files. But It seems PyQuery() is not act as excepted:

This Code Runs OK:

from pyquery import PyQuery
_xml = '''
<?xml verion="1.0" encoding="UTF-8"?>
<node>
	<data></data>
</node>
'''

print( PyQuery(_xml) )

But If i Trimed the _xml , It raised Exception:

from pyquery import PyQuery
_xml = '''<?xml verion="1.0" encoding="UTF-8"?>
<node>
	<data></data>
</node>
'''

print( PyQuery(_xml) )
Traceback (most recent call last):
  File "Test.py", line 17, in <module>
    print( PyQuery(_xml) )
  File "C:\Python38\lib\site-packages\pyquery\pyquery.py", line 217, in __init__
    elements = fromstring(context, self.parser)
  File "C:\Python38\lib\site-packages\pyquery\pyquery.py", line 57, in fromstring
    result = getattr(etree, meth)(context)
  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.

Is this a BUG ?

@gawel
Copy link
Owner

gawel commented Jul 22, 2023

As you can see the error is raised by the lxml parser so you should post another issue on this project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants