Skip to content

Instantly share code, notes, and snippets.

@oz123
Created July 26, 2017 12:26
Show Gist options
  • Save oz123/7e95cd76c48a16d68492383b18863239 to your computer and use it in GitHub Desktop.
Save oz123/7e95cd76c48a16d68492383b18863239 to your computer and use it in GitHub Desktop.
basic bottle authentication
from bottle import Bottle, auth_basic, request, run
app = Bottle()
def check(user, passwd):
if user == 'oz123':
return True
return False
@app.route('/')
def user_page():
return "EASY"
@app.route('/user/')
@auth_basic(check)
def user_page():
print('auth', request.auth)
print('remote_addr', request.remote_addr)
return "Yay - you made it!"
if __name__ == '__main__':
print("Starting server")
run(app=app, host='0.0.0.0', port=8080, reloader=True)
curl -u oz123:xyz http://localhost:8080/user/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment