I am learning Bottle framework and new to Python. Just stumbled upon this difficulty. When I write a simple method to return a an Arabic string like:
@route('/hello')
def hello():
return u'سلام'
I get this error message in the terminal:
SyntaxError: Non-ASCII character '\xd8' in file hello.py on line 15, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
I have imported all from bottle and tried adding other methods mentioned in the docs where it talks about "Changing the Default Encoding" however I was unable to resolve the issue. So I appreciate your hints.
Here is my code for testing:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bottle import *
@route('/hello')
def hello():
return u'سلام'
run(host='127.0.0.1', port=8080,reloader=True)
In my editor, I choose File > Save As..., then select Unicode (UTF-8) as Text Encoding, and saved as hello.py
Then download the lastest version of bottle.py from github, and put it in the same folder(e.g. bottle-test) with hello.py
Run it, and seems no problems at all.
~$ python --version
Python 2.6.7
~$ cd bottle-test
bottle-test$ python hello.py
just add
# -*- coding: whatever-encoding-you-use -*-
on the top of your file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With