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

  • Home
  • SEARCH
  • 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 8388655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:31:09+00:00 2026-06-09T18:31:09+00:00

From this block of code: class MainHandler(webapp2.RequestHandler): def get(self): template_values = {given_sentence:’put a sentence

  • 0

From this block of code:

class MainHandler(webapp2.RequestHandler):
    def get(self):

        template_values = {"given_sentence":'put a sentence here'}
        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render(template_values))

    def post(self):
        nb = naivebayes(getfeatures)
        sampletrain(nb)
        given_sentence = self.request.get("given_sentence").encode('utf-8')
      #  given_sentence = self.request.get("given_sentence")
        spam_result = nb.classify(given_sentence)
        submit_button = self.request.get("submit_button")
        if submit_button:
            self.redirect('/test_result?spam_result=%s&given_sentence=%s' % (spam_result, given_sentence))

I’m getting this error:

  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\CG\Desktop\Google Drive\Sci&Tech\projects\naivebayes\main.py", line 262, in post
    self.redirect('/test_result?spam_result=%s&given_sentence=%s' % (spam_result, given_sentence))
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 608, in redirect
    response=self.response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1767, in redirect
    uri = str(urlparse.urljoin(request.url, uri))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 82: ordinal not in range(128)
INFO     2012-08-16 20:02:52,229 dev_appserver.py:2952] "POST / HTTP/1.1" 500 -
INFO     2012-08-16 20:05:06,858 py_zipimport.py:148] zipimporter('C:\\Python27\\lib\\site-packages\\pyyaml-3.10-py2.7-win32.egg', '')
ERROR    2012-08-16 20:05:08,230 webapp2.py:1553] 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\CG\Desktop\Google Drive\Sci&Tech\projects\naivebayes\main.py", line 262, in post
    self.redirect('/test_result?spam_result=%s&given_sentence=%s' % (spam_result, given_sentence))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)

When the value of given_sentence is something like this: productos farmacéuticos comprar ahora.

I my python code is in utf-8. I also put on my templates (in the <head> tag) this line: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>.

The problem seens to be in passing a non-ASCII sentence through the url. If I try this (“productos comprar ahora”), it’s ok:

http://localhost:8084/test_result?spam_result=good&given_sentence=productos%20comprar%20ahora

But If I try this: “productos farmacéuticos comprar ahora” I got the above error. Isn’t it possible to pass through url a non-ASCII value? Or is there some other mistake here that I’m not seeing?

  • 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-09T18:31:10+00:00Added an answer on June 9, 2026 at 6:31 pm

    This is a basic Python encoding issue. You are trying to put a non-ASCII string into an ASCII one. Use unicode instead (note the u):

    self.redirect(u'/test_result?spam_result=%s&given_sentence=%s' % (spam_result, given_sentence))
    

    (and drop the encode call on getting given_sentence).

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

Sidebar

Related Questions

This line of code: contract = Contract.get_by_id(contract_id) From this block: class MainHandler(webapp2.RequestHandler): def get(self):
This line of code: geted_nickname = user.nickname() Of this Handler: class MainHandler(webapp2.RequestHandler): def get(self):
i am having trouble deciphering this block of code from doctrine documentation /** @Entity
I am trying to get some data from my database. This is my code
I've just read this snippet from another answer : When you create a block
From this code I can call bmwCars.CopyToDataTable() as I expected. var bmwCars = from
From this site: http://www.toymaker.info/Games/html/vertex_shaders.html We have the following code snippet: // transformations provided by
From this code: int x = 5; int other = 10; vector<int*> v_ptr; v_ptr.push_back(&x);
from this code will show in original color how can i change it to
I tested this block of code and find that the GetInts method does not

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.