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 8433111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:17:55+00:00 2026-06-10T06:17:55+00:00

I am having trouble with unicode in a script I am writing. I have

  • 0

I am having trouble with unicode in a script I am writing. I have scoured the internet, including this site and I have tried many things, and I still have no idea what is wrong.

My code is very long, but I will show an excerpt from it:

raw_results = get_raw(args)
write_raw(raw_results)
parsed_results = parse_raw(raw_results)
write_parsed(parsed_results)

Basically, I get raw results, which is in XML, encoded in UTF-8. Writing the RAW data has no problems. But writing the parsed data is. So I am pretty sure the problem is inside the function that parses the data.

I tried everything and I do not understand what the problem is. Even this simple line gives me an error:

def parse_raw(raw_results)
    content = raw_results.replace(u'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', u'')

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd7 in position
570: ordinal not in range(128)

Ideally I would love to be able to work with unicode and have no problems, but I also have no issue with replacing/ignoring any unicode and using only regular text. I know I have not provided my full code, but understand that it’s a problem since it’s work-related. But I hope this is enough to get me some help.

Edit: the top part of my parse_raw function:

from xml.etree.ElementTree import XML, fromstring, tostring
def parse_raw(raw_results)    
    raw_results = raw_results.decode("utf-8")
    content = raw_results.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '')
    content = "<root>\n%s\n</root>" % content
    mxml = fromstring(content)

Edit2:: I think it would be a good idea to point out that the code works fine UNLESS there are special characters. When it’s 100% English, no problem; whenever any foreign letters or accented letters are involved is when the issues arise.

  • 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-06-10T06:17:56+00:00Added an answer on June 10, 2026 at 6:17 am

    Thank you everyone for the input and the nudges. I have subsequently solved my own problem by going over my code for the millionth time with a fine-toothed comb, and I have found the culprit. And I have solved all my problems now.

    For anyone with a similar problem, I have the following information that could help you:

    • Use the codecs module for writing your files.
    • Do not try to handle it all along your code, your code should ignore any type of character set throughout methods, and should have specific methods or calls to methods where only you modify the charset. (this helped me find the problem)

    My problem was that at a certain point I was trying to turn unicode into unicode. And in another place I was trying to turn normal ASCII into ASCII again. So whenever I solved one issue, another arose and I figured it was the same problem.

    Break your issue into sections… and then you might find your problem!

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

Sidebar

Related Questions

i have a json file with unicode characters, and i'm having trouble to parse
Having trouble wrapping a BOOL value in NSValue. I tried this: [NSValue valueWithPointer:[NSNumber numberWithBool:YES]]
I'm having trouble reading in supplementary unicode characters using Java. I have a file
I am having trouble using a NSString with unicode characters like 'ç' and 'ñ'.
Having trouble framing this assertion in Rspec for my rails app. A User has
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I am having trouble writing a query on a mysql table of user activity
i'm having some trouble figuring out how to save unicode into a file in
I'm having trouble handling escaped unicode characters in R, specifically those encountered when grabbing
We are having trouble getting a Unicode string to convert to a UTF-8 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.