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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:28:43+00:00 2026-05-13T22:28:43+00:00

I have been studying unicode and its Python implementation now for two days, and

  • 0

I have been studying unicode and its Python implementation now for two days, and I think I’m getting a glimpse of what it is about. Just to get confident, I’m asking if my assumptions for my current problems are correct.

In Django, forms give me unicode strings which I suspect to be “broken”. Unicode strings in Python should be encoded in UTF-8, is that right? After entering the string “fähre” into a text field, the browser sends the string “f%c3%a4hre” in the POST request (checked via wireshark). When I retrieve the value via form.cleaned_data, I’m getting the string u’f\xa4hre’ (note it is a unicode string), though. As far as I understand that, that is ISO-8859-1-encoded unicode string, which is incorrect. The correct string should be u’f\xc3\xa4hre’, which would be a UTF-8-encoded unicode string. Is that a Django bug or is there something wrong with my understanding of it?
To fix the issue, I wrote a function to apply it to any text input from Django forms:

def fix_broken_unicode(s):
    return unicode(s.encode(u'utf-8'), u'iso-8859-1')

which does

>>> fix_broken_unicode(u'f\xa4hre')
u'f\xc3\xa4hre'

That doesn’t seem very elegant to me, but setting Django’s settings.DEFAULT_CHARSET to ‘utf-8′ didn’t help, nor did anything else. I am trying to work with unicode throughout the whole application so I won’t get any weird errors later on, but it obviously does not suffice to mark all strings with u’…’.

Edit: Considering the answers from Dirk and sth, I will now save the strings to the database as they are. The real problem was that I was trying to urlencode these kinds of strings to use them as input for the Twitter API etc. In GET or POST requests, though, UTF-8 encoding is obviously expected which the standard urllib.urlencode() function does not process correctly (throws exceptions). Take a look at my solution in the pastebin and feel free to comment on it also.

  • 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-13T22:28:44+00:00Added an answer on May 13, 2026 at 10:28 pm

    u'f\xa4hre'is a unicode string, not encoded as anything. The unicode codepoint 0xa4 is the character ä. It is not really important that ä would also be encoded as byte 0xa4 in ISO-8859-1.

    The unicode string can contain any unicode characters without encoding them in some way. For example 轮渡 would be represented as u'\u8f6e\u6e21', which are simply two unicode codepoints. The UTF-8 encoding would be the much longer '\xe8\xbd\xae\xe6\xb8\xa1'.

    So there is no need to fix the encoding, you are just seeing the internal representation of the unicode string.

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

Sidebar

Related Questions

I have been studying python for quite sometime now and very recently I decided
I am new to Python and have been studying its fundementals for 3 months
these days I have been studying about NP problems, computational complexity and theory. I
I just started studying programming about 6 months ago and I have really been
I have been studying DDD in-depth on my own time; reading everything about it
I have been studying swing for developing gui applications since a few days. The
I'm a Maven newbie, have been studying Maven for a week now, have 5
I have been studying as much as I can about the Module Pattern suggested
I have been studying (old) 3D rendering techniques for the past weeks and think
I've been studying Python 3 recently and I have come across a conundrum: I

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.