From 4332f7a640792857a21e982e23fe4c57758763bf Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 17 May 2020 21:44:12 +0200 Subject: [PATCH] Better detection of localhost for kobo sync (possibly related to #1400) --- cps/kobo_auth.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cps/kobo_auth.py b/cps/kobo_auth.py index 7fa778cd..0f6cd174 100644 --- a/cps/kobo_auth.py +++ b/cps/kobo_auth.py @@ -121,7 +121,11 @@ kobo_auth = Blueprint("kobo_auth", __name__, url_prefix="/kobo_auth") @kobo_auth.route("/generate_auth_token/") @login_required def generate_auth_token(user_id): - host = ':'.join(request.host.rsplit(':')[0:-1]) + host_list = request.host.rsplit(':') + if len(host_list) == 1: + host = ':'.join(host_list) + else: + host = ':'.join(host_list[0:-1]) if host.startswith('127.') or host.lower() == 'localhost' or host.startswith('[::ffff:7f'): warning = _('PLease access calibre-web from non localhost to get valid api_endpoint for kobo device') return render_title_template(