question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Under Python 3.4.2 I get an error:

XML input:

<?xml version="1.0"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>

Python snippet:

with open(xml_file) as f:
    d = xmltodict.parse(f, xml_attribs=True)

Error message:

Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/xmltodict.py", line 246, in parse
    parser.ParseFile(xml_input)
TypeError: read() did not return a bytes object (type=str)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "./xml2json.py", line 27, in <module>
    print(convert(sys.argv[1]))
  File "./xml2json.py", line 17, in convert
    d = xmltodict.parse(f, xml_attribs=xml_attribs)
  File "/usr/lib/python3.4/site-packages/xmltodict.py", line 248, in parse
    parser.Parse(xml_input, True)
TypeError: '_io.TextIOWrapper' does not support the buffer interface

Under Python 2.7 this example works fine.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
jabbalacicommented, Dec 29, 2014

I found the solution: you need to open the XML input as binary:

with open(xml_file, "rb") as f:
    d = xmltodict.parse(f, xml_attribs=True)

Notice the “rb” mode instead of “r”.

0reactions
martinblechcommented, Jan 31, 2017

I didn’t make the parser, can’t say. Try asking in stackoverflow.com, someone out there might know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python tracker: List of issues
ID GH Activity Status Creator Assigned To Type Msgs 2771 47020 7 months ago open gvanrossum ezio.melotti behavior 145 24778 68966 8 months ago open...
Read more >
Common migration problems — Supporting Python 3
The biggest problem you may encounter relates to one of the most important changes in Python 3; strings are now always Unicode. This...
Read more >
Why is the Migration to Python 3 Taking So Long?
The idea behind developing Python 3 was to implement a single big change that got rid of a legacy problem in Python: rendering...
Read more >
Python 3 Issues - Gradescope Autograder Documentation
If you're having issues with your Python 3 autograder not starting and you're overriding the system version of python3 , it may be...
Read more >
How to install the latest Python 3 on Mac with no issues
I tried several approaches to installing Python 3 on Mac, and this is what worked as the best solution for these three goals:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found