Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIskander Ismagilov
13,298 Points'utf-8' codec can't decode byte 0xcf [SOLVED]
Hi, everybody! I have a problem, when I try to launch this code locally, using PowerShell on Windows 7:
from flask import Flask
app = Flask(__name__)
app.route('/')
app.route('/<name>')
def index(name="Treehouse"):
return "Hello from {}".format(name)
app.run(debug=True, port=8000, host='127.0.0.1') # I changed host, so I can get to the page using my browser.
and when I run this script, it throws an exception:
File "c:\python35\Lib\socket.py", line 658, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 2: invalid continuation byte
Is it because of some problem with utf to convert some symbols in uncode?
2 Answers
Iskander Ismagilov
13,298 PointsThank's Chris,
I got it, I found this document: http://bugs.python.org/issue9377. So the prooblem was because of non-ASCII symbols in the host name of my computer, so after I figure out that the name of my computer and the host name of my computer are the same, I just changed it.
Chris Freeman
Treehouse Moderator 68,428 PointsNot sure about the byte decode issue, but there is another issue with your code.
The app.route
decorators need to be prefixed with an at sign @
@app.route('/')
@app.route('/<name>')
def index(name="Treehouse"):
return "Hello from {}".format(name)
Post back if that's not the issue.
Chris Freeman
Treehouse Moderator 68,428 PointsFantastic! I would not have figured it out with my current environment
Chris Freeman
Treehouse Moderator 68,428 PointsChris Freeman
Treehouse Moderator 68,428 PointsMoved to answer. Mark Best Answer.