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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:55:59+00:00 2026-05-19T09:55:59+00:00

I have some text coming from the web as such: £6.49 Obviously I would

  • 0

I have some text coming from the web as such:

£6.49

Obviously I would like this to be displayed as:

£6.49

I have tried the following so far:

s = url['title']
s = s.encode('utf8')
s = s.replace(u'Â','')

And a few variants on this (after finding it on this very same forum)

But still no luck as I keep getting:

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

Could anyone help me getting this right?

UPDATE:

Adding the repr examples and content type

u'Star Trek XI £3.99'
u'Oscar Winners Best Pictures Box Set \xc2\xa36.49'
Content-Type: text/html; charset=utf-8

Thanks in advance.

  • 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-19T09:55:59+00:00Added an answer on May 19, 2026 at 9:55 am

    If, s=url['title'] makes s equal to this:

    In [48]: s=u'Oscar Winners Best Pictures Box Set \xc2\xa36.49'
    

    Then the problem is

    1. in the code that defines url,
    2. or else the content from the web is
      mal-formed.

    If Case 1, we’d need to see the code that defines url.

    If Case 2, a quick-and-dirty workaround would be to encode the unicode object s with the raw-unicode-escape codec:

    In [49]: print(s)
    Oscar Winners Best Pictures Box Set £6.49
    
    In [50]: print(s.encode('raw-unicode-escape'))
    Oscar Winners Best Pictures Box Set £6.49
    

    See also this SO question.


    Regarding titles like s=u'Star Trek XI £3.99': Again, it would be nice fix the problem before it gets to this stage — perhaps by looking at how url is defined. But assuming the content from the web is mal-formed, a workaround would be:

    In [86]: import re
    
    In [87]: print(re.sub(r'&#x([a-fA-F\d]+);',lambda m: unichr(int(m.group(1),base=16)),s))
    Star Trek XI £3.99
    

    A little bit of explanation:

    Note that

    In [51]: x=u'£'
    In [53]: x.encode('utf-8')
    Out[53]: '\xc2\xa3'
    

    So the unicode object u'£', encoded with the utf-8 codec, becomes the string object '\xc2\xa3'.

    Somehow, url['title'] is getting defined to be the unicode object
    u'\xc2\xa3'. (The u makes a big difference!)

    Thus we have u'\xc2\xa3' when we desire '\xc2\xa3'.
    Encoding the unicode object u'\xc2\xa3' with the raw-unicode-escape codec transforms it to '\xc2\xa3'.

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

Sidebar

Related Questions

I have some code that looks like the following coming back from an XHR
I have to render some text to a web page. The text is coming
I have some text that is stored in a variable like this: <div class=foo>text
I have some text in a UITextView, that I would like to have show
I'm coming from a c# background, and I do this: Console.Write(some text + integerValue);
I have, for example, markup like this <div id=content> <p>Here is some wonderful text,
I have some text that uses Unicode punctuation, like left double quote, right single
I have some text area field in my grails application. I got the following
i have a string like this: some_string = A simple demo of SMS text
I have a listView with some data coming from a server.I want to do

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.