Question

I am trying to make a web page using Bottle.py, Mongodb and Python.

I had this tag on top of my python 2.7 code:

# #-- coding: latin1 --

I use the coding for getting bottle requests such as:

CheckboxTr= bottle.request.forms.getlist("CheckboxTr")
tags = bottle.request.forms.get("tags")

I also have meta charset="•ISO-8859-1" on top of each web page, and everything worked fine. However, when I tried to migrate to python 3.4 I get no error message, but my coding seems to be UTF-8 instead of Latin-1 (accent characters won't print as they should).

I hope you can help me. I am missing something for the migration to work, maybe they updated the coding name or something, but I have been reading python 3.4 coding and can´t find my error.

This is the code:

@bottle.post('/newpost')
def post_newpost():
    title = bottle.request.forms.get("subject")
    post = bottle.request.forms.get("body")
    beneficios = bottle.request.forms.get("beneficios")
    CheckboxTramite= bottle.request.forms.getlist("CheckboxTramite")
    cookie = bottle.request.get_cookie("session")
    username = sessions.get_username(cookie)
    dependencia = sessions.get_dependencia(cookie)

return bottle.template("newpost_template1", dict(subject="", body = "", errors="", tags="", username=username, dependencia=dependencia, beneficios="", CheckboxTramite=[],))
Was it helpful?

Solution

I don't know why the encoding for Bottle's output would change, since it's documented as being utf-8 by default. However the documentation states that you can change it by setting the Response.charset attribute. Have a look at the example under "Changing the Default Encoding".

This has nothing to do with the encoding of your Python source files, as some of the comments to the question are hinting.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top