Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion urequests/metadata.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
srctype = micropython-lib
type = module
version = 0.6
version = 0.6.1
author = Paul Sokolovsky
2 changes: 1 addition & 1 deletion urequests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sdist_upip

setup(name='micropython-urequests',
version='0.6',
version='0.6.1',
description='urequests module for MicroPython',
long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.",
url='https://github.com/micropython/micropython-lib',
Expand Down
11 changes: 10 additions & 1 deletion urequests/urequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def json(self):
return ujson.loads(self.content)


def request(method, url, data=None, json=None, headers={}, stream=None):
def request(method, url, data=None, json=None, headers={}, stream=None, auth=None):
if auth is not None:
headers.update(encode_basic_auth(auth[0], auth[1]))

try:
proto, dummy, host, path = url.split("/", 3)
except ValueError:
Expand Down Expand Up @@ -122,3 +125,9 @@ def patch(url, **kw):

def delete(url, **kw):
return request("DELETE", url, **kw)

def encode_basic_auth(username, password):
import ubinascii
formated = b"{}:{}".format(username, password)
formated = ubinascii.b2a_base64(formated)[:-1].decode("ascii")
return {'Authorization' : 'Basic {}'.format(formated)}