kopia lustrzana https://github.com/micropython/micropython-lib
urequests: Add Basic Authentication support.
Usage matches the shorthand version described in https://requests.readthedocs.io/en/latest/user/authentication/#basic-authenticationpull/502/head
rodzic
106c28a4d7
commit
e7e8eff86b
|
@ -33,7 +33,17 @@ class Response:
|
||||||
return ujson.loads(self.content)
|
return ujson.loads(self.content)
|
||||||
|
|
||||||
|
|
||||||
def request(method, url, data=None, json=None, headers={}, stream=None, parse_headers=True):
|
def request(
|
||||||
|
method, url, data=None, json=None, headers={}, stream=None, parse_headers=True, auth=None
|
||||||
|
):
|
||||||
|
if auth is not None:
|
||||||
|
import ubinascii
|
||||||
|
|
||||||
|
username, password = auth
|
||||||
|
formated = b"{}:{}".format(username, password)
|
||||||
|
formated = str(ubinascii.b2a_base64(formated)[:-1], "ascii")
|
||||||
|
headers["Authorization"] = "Basic {}".format(formated)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
proto, dummy, host, path = url.split("/", 3)
|
proto, dummy, host, path = url.split("/", 3)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
Ładowanie…
Reference in New Issue