Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 46e0fa1

Browse files
author
Fabian Schmitt
committed
urequests: Added Basic Authentication (as in `requests.request())
1 parent f20d89c commit 46e0fa1

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

‎urequests/metadata.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
srctype = micropython-lib
22
type = module
3-
version = 0.6
3+
version = 0.6.1
44
author = Paul Sokolovsky

‎urequests/setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sdist_upip
88

99
setup(name='micropython-urequests',
10-
version='0.6',
10+
version='0.6.1',
1111
description='urequests module for MicroPython',
1212
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.",
1313
url='https://github.com/micropython/micropython-lib',

‎urequests/urequests.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def json(self):
3232
return ujson.loads(self.content)
3333

3434

35-
def request(method, url, data=None, json=None, headers={}, stream=None):
35+
def request(method, url, data=None, json=None, headers={}, stream=None, auth=None):
36+
if auth is not None:
37+
headers.update(encode_basic_auth(auth[0], auth[1]))
38+
3639
try:
3740
proto, dummy, host, path = url.split("/", 3)
3841
except ValueError:
@@ -122,3 +125,9 @@ def patch(url, **kw):
122125

123126
def delete(url, **kw):
124127
return request("DELETE", url, **kw)
128+
129+
def encode_basic_auth(username, password):
130+
import ubinascii
131+
formated = b"{}:{}".format(username, password)
132+
formated = ubinascii.b2a_base64(formated)[:-1].decode("ascii")
133+
return {'Authorization' : 'Basic {}'.format(formated)}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /