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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:43:47+00:00 2026-06-10T13:43:47+00:00

I’m learning Django. There is a search bar. That is intended to be used

  • 0

I’m learning Django. There is a search bar. That is intended to be used with russian words.
The word is caught with a simple form.

How can I encode the word to utf-8 right at the beginning ? It creates the UnicodeEncodeError at some point because of this.
Or what are the ways to change the original request?

The database is set to utf-8.

Thank you.

Here is the Traceback

Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)

File "/home/teodor/moldova/search/views.py" in results
  27.   return render_to_response(template_name, locals(), context_instance = RequestContext(request))

File "/usr/local/lib/python2.6/dist-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in render_to_string
  176.         return t.render(context_instance)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  140.             return self._render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)

File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)

File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)

File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)

File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)

File "/usr/local/lib/python2.6/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)

File "/usr/local/lib/python2.6/dist-packages/django/template/base.py" in render
  1178.                     _dict = func(*resolved_args, **resolved_kwargs)

File "/home/teodor/moldova/search/templatetags/search_tags.py" in pagination_links
  23.   params = urllib.urlencode(raw_params)

File "/usr/lib/python2.6/urllib.py" in urlencode
  1267.             v = quote_plus(str(v))

Exception Type: UnicodeEncodeError at /search/results/
Exception Value: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

I did a search for word: Найти

  • 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-10T13:43:49+00:00Added an answer on June 10, 2026 at 1:43 pm

    I don’t have much experience with this, but as per Jonathan “Wolf” Rentzsch’s guide to using UTF-8 on the web, you might want to try adding the accept-charset="UTF-8" attribute to your <form> tag.

    Where are you seeing the UnicodeEncodeError? Can you show us some code?

    Edit: ah, okay. Yup — I think Django provides all text as Unicode objects. If I’m understanding the traceback correctly, the issue occurs when you call str on this unicode object to use it with urllib.quote_plus.

    I think you need to provide urllib.quote_plus with text encoded in ASCII (See e.g. Is there a unicode-ready substitute I can use for urllib.quote and urllib.unquote in Python 2.6.5?).

    And as per this question, I think you can do that like this:

    import unicodedata
    v_as_ascii = unicodedata.normalize('NFKD', v.decode('UTF-8')).encode('ascii', 'ignore')
    v = quote_plus( v_as_ascii )
    

    (I haven’t tested any of this though, so I could be entirely wrong. Hopefully someone who has experience with this stuff will come by.)

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

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.