Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Don't panic.


devel / comp.lang.python / Re: basic auth request

SubjectAuthor
o Re: basic auth requestChris Angelico

1
Re: basic auth request

<mailman.417.1629220602.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14646&group=comp.lang.python#14646

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: basic auth request
Date: Wed, 18 Aug 2021 03:16:27 +1000
Lines: 33
Message-ID: <mailman.417.1629220602.4164.python-list@python.org>
References: <07b8928a-fe1f-958b-3ee2-d0f6ec51d414@everest.reportlab.co.uk>
<CAPTjJmqs2sgryzyYDmVnyid8Q9ZEOFTPsNBLD7oFu4T7UhiQmg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 5azfDMin0v80QEubxKx+UgM+kv6FUOmjnbe+sFEwCFNw==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Q/9Uz9p2;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'utf-8': 0.07; '(assuming':
0.09; '18,': 0.09; 'aug': 0.09; 'auth': 0.09; 'everywhere': 0.09;
'porting': 0.09; '%s"': 0.16; 'becker': 0.16; 'chrisa': 0.16;
'conversion': 0.16; 'decode.': 0.16; 'encoding': 0.16;
'encoding,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris
angelico': 0.16; 'input.': 0.16; 'python3': 0.16; 'robin': 0.16;
'standard,': 0.16; 'url-ip:151.101.1.69/32': 0.16; 'url-
ip:151.101.129.69/32': 0.16; 'url-ip:151.101.193.69/32': 0.16;
'url-ip:151.101.65.69/32': 0.16; 'url:questions': 0.16;
'url:stackoverflow': 0.16; 'value?': 0.16; 'wrote:': 0.16;
'issue': 0.20; 'option': 0.21; 'to:addr:python-list': 0.23;
'probably': 0.24; 'idea': 0.25; 'error': 0.28; 'subject:request':
0.29; 'text': 0.29; 'there': 0.31; 'but': 0.31; "i'm": 0.32;
'skip:w 40': 0.32; 'to:name:python': 0.32; 'url-
ip:151.101.129/24': 0.32; 'url-ip:151.101.193/24': 0.32; 'message-
id:@mail.gmail.com': 0.33; 'using': 0.33; 'received:209.85.166':
0.33; 'header:In-Reply-To:1': 0.33; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'way': 0.37; "that's": 0.37;
'received:209.85': 0.38; "it's": 0.38; 'received:209': 0.38;
'use': 0.38; 'skip:r 30': 0.61; 'skip:b 10': 0.62; 'your': 0.64;
'clear': 0.65; 'direct': 0.73; '2021': 0.84; 'safe,': 0.91;
'safely': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=QFmqu1ydCW8HrFscxrMeBdjMeNsbrB4Oxbivv7Cl85g=;
b=Q/9Uz9p2KFSg8V04ccqQeKhxtWYqaBGSusejJumZ6RaUUADptKbCeo2azd7MhQY4Nt
gbHdI/HFu32YMuAtz/Qi3FH0zzF1709uQQJMImpzqWoxqKmXkX+1RcRJXBzrRjJ/IZIq
plcFJfbQtbWj55LZthahy3lMVl3wwxv9ZZpkFVK+NFuCl9OjTl5rLQZlKo62M4o7hIFk
vdAph+JA/Qu5F4rmNa8/Y9tIuA7p8vdXCx2Bskhiami/B3bvd5IjvnNuuwfv71fKOufj
3PizWx2JmgyEn6aZoNRo9Yb8fsGNHWBg7cERh/FV9QKMjq0SRvuGEOS2fY3r/UHBikkp
M+Dw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=QFmqu1ydCW8HrFscxrMeBdjMeNsbrB4Oxbivv7Cl85g=;
b=RKYWqDCyZdmwY2nLoyn8W9IFW+dXCx+XCehOIshjK8aNvGIC05ZVA+7xNk2BsF1Klo
f8JmMSQ5MMxaVLwFTN3MzxrV+SkZMSU6V2zJte/FHkg3iKhE89US1k37OwV6JuElFKMz
clCyLOsQSdGwLEZOmCh2DlE20QpfseAuBTKgV3wOUh6JD0Mgam6Icgho4m8cZKoJ/Nmh
o96zPYFfQA5H0hpfoEhOCRirhqGfz8MRzsvwFQYZtWfUp0B3X72fKK4aO4wrVJwlOoL5
gUo9y/Uyn6vOh3Ma9U7nfqn+cYSh52rr6Hb2pXtiHhh8uGxvaeMXe+ekeK0G8nKviRd0
FVvA==
X-Gm-Message-State: AOAM5335IFFevz/e0IGzkYrZxPu+cD9tq0A0gKfyn+QVfwvkFNYIeq+M
7hdqeWHRofPT9OtHThsuhAbmSRPLdbsngrr+XZ9eRaOfsoE=
X-Google-Smtp-Source: ABdhPJxlVsPTUr/UFjy2HjeNE9DKlMBj2nMKrA5ASkr+U8MlNpCtD9/fcQcXNGOq+ZQOjyWUiosMvUS4CuyuGIW3YhA=
X-Received: by 2002:a02:cbb0:: with SMTP id v16mr3901221jap.114.1629220598754;
Tue, 17 Aug 2021 10:16:38 -0700 (PDT)
In-Reply-To: <07b8928a-fe1f-958b-3ee2-d0f6ec51d414@everest.reportlab.co.uk>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmqs2sgryzyYDmVnyid8Q9ZEOFTPsNBLD7oFu4T7UhiQmg@mail.gmail.com>
X-Mailman-Original-References: <07b8928a-fe1f-958b-3ee2-d0f6ec51d414@everest.reportlab.co.uk>
 by: Chris Angelico - Tue, 17 Aug 2021 17:16 UTC

On Wed, Aug 18, 2021 at 3:04 AM Robin Becker <robin@reportlab.com> wrote:
>
> While porting an ap from python2.7 to python3 I see this
>
> base64string = base64.b64encode('%s:%s' % (wsemail, wspassword))
> request.add_header("Authorization", "Basic %s" % base64string)
>
> in python3.x I find this works
>
> base64string = base64.b64encode(('%s:%s' % (wsemail, wspassword)).encode('ascii')).decode('ascii')
> request.add_header("Authorization", "Basic %s" % base64string)
>
> but I find the conversion to and from ascii irksome. Is there a more direct way to create the basic auth value?
>
> As an additional issue I find I have no clear idea what encoding is allowed for the components of a basic auth input.

Hmm, I'm not sure what type your wsemail and wspassword are, but one
option would be to use bytes everywhere (assuming your text is all
ASCII).

wsemail = b"robin@becker.example"
wspassword = b"correct-battery-horse-staple"

base64string = base64.b64encode(b'%s:%s' % (wsemail, wspassword))

But otherwise, it's probably safest to keep using the encode and
decode. As to the appropriate encoding, that's unclear according to
the standard, but UTF-8 is probably acceptable. ASCII is also safe, as
it'll safely error out if it would be ambiguous.

https://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor