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 trialRobert Martinez
3,725 PointsPython flask error: gaierror: [Errno -2] Name or service not known
this is my code:
from flask import Flask
app = Flask(name)
@app.route('/') def index(): return "Hello"
What am i doing wrong??? not sure why im getting the error "Name or service not known" Any suggestions??
1 Answer
Patrick Hooper
39,003 PointsI'm not sure if some pieces of your code got transformed or formatted strangely when you pasted it in, but the following should work:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "Hello"
The differences between that and what I see in your question are:
-
app = Flask(name)
should beapp = Flask(__name__)
.__name__
is a special Python variable that needs the double underscores surrounding it. - Formatting for the decorator and the function declaration. Python pays attention to things like line breaks and indentation in your code, so having all that done properly is important to correct code execution.