Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7441285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:59:13+00:00 2026-05-29T10:59:13+00:00

I’ve been fighting with this for an hour now. I’m parsing an XML-string with

  • 0

I’ve been fighting with this for an hour now. I’m parsing an XML-string with iterparse. However, the data is not encoded properly, and I am not the provider of it, so I can’t fix the encoding.

Here’s the error I get:

lxml.etree.XMLSyntaxError: line 8167: Input is not proper UTF-8, indicate encoding !
Bytes: 0xEA 0x76 0x65 0x73

How can I simply ignore this error and still continue on parsing? I don’t mind, if one character is not saved properly, I just need the data.

Here’s what I’ve tried, all picked from internet:

data = data.encode('UTF-8','ignore')
data = unicode(data,errors='ignore')
data = unicode(data.strip(codecs.BOM_UTF8), 'utf-8', errors='ignore')

Edit:
I can’t show the url, as it’s a private API and involves my API key, but this is how I obtain the data:

ur = urlopen(url)
data = ur.read()

The character that causes the problem is: å, I guess that ä & ö, etc, would also break it.

Here’s the part where I try to parse it:

def fast_iter(context, func):
    for event, elem in context:
        func(elem)
        elem.clear()
        while elem.getprevious() is not None:
            del elem.getparent()[0]
    del context

def process_element(elem):
    print elem.xpath('title/text( )')

context = etree.iterparse(StringIO(data), tag='item')
fast_iter(context, process_element)

Edit 2:
This is what happens, when I try to parse it in PHP. Just to clarify, F***ing Åmål is a drama movie =D

The file starts with <?xml version="1.0" encoding="UTF-8" ?>

Here’s what I get from print repr(data[offset-10:offset+60]):

ence des r\xeaves, La</title>\n\t\t<year>2006</year>\n\t\t<imdb>0354899</imdb>\n
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:59:13+00:00Added an answer on May 29, 2026 at 10:59 am

    You say:

    The character that causes the problem is: å,

    How do you know that? What are you viewing your text with?

    So you can’t publish the URL and your API key; what about reading the data, writing it to a file (in binary mode), and publishing that?

    When you open that file in your web browser, what encoding does it detect?

    At the very least, do this

    data.decode('utf8') # where data is what you get from ur.read()
    

    This will produce an exception that will tell you the byte offset of the non-UTF-8 stuff.

    Then do this:

    print repr(data[offset-10:offset+60])

    and show us the results.

    Assuming the encoding is actually cp1252 and decoding the bytes in the lxml error message:

    >>> guff = "\xEA\x76\x65\x73"
    >>> from unicodedata import name
    >>> [name(c) for c in guff.decode('1252')]
    ['LATIN SMALL LETTER E WITH CIRCUMFLEX', 'LATIN SMALL LETTER V', 'LATIN SMALL LE
    TTER E', 'LATIN SMALL LETTER S']
    >>>
    

    So are you seeing e-circumflex followed by ves, or a-ring followed by ves, or a-ring followed by something else?

    Does the data start with an XML declaration like <?xml version="1.0" encoding="UTF-8"?>? If not, what does it start with?

    Clues for encoding guessing/confirmation: What language is the text written in? What country?

    UPDATE based on further information supplied.

    Based on the snippet that you showed in the vicinity of the error, the movie title is “La science des rêves” (the science of dreams).

    Funny how PHP gags on “F***ing Åmål” but Python chokes on French dreams. Are you sure that you did the same query?

    You should have told us it was IMDB up front, you would have got your answer much sooner.

    SOLUTION before you pass data to the lxml parser, do this:

    data = data.replace('encoding="UTF-8"', 'encoding="iso-8859-1"')
    

    That’s based on the encoding that they declare on their website, but that may be a lie too. In that case, try cp1252 instead. It’s definitely not iso-8859-2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an XML file, the creators of it stuck in a bunch social
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.