Skip to content

Commit 5b2e602

Browse files
authored
Update network.py
Modify the `wget()` method to optionally allow sending request headers.
1 parent 01f050e commit 5b2e602

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

adafruit_portalbase/network.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,21 @@ def get_local_time(self, location=None):
248248

249249
return reply
250250

251-
def wget(self, url, filename, *, chunk_size=12000):
251+
def wget(self, url, filename, *, chunk_size=12000, headers=None):
252252
"""Download a url and save to filename location, like the command wget.
253253
254254
:param url: The URL from which to obtain the data.
255255
:param filename: The name of the file to save the data to.
256256
:param chunk_size: how much data to read/write at a time.
257+
:param headers: a dict of headers to send along in the request.
257258
258259
"""
259260
print("Fetching stream from", url)
260261

261262
self.neo_status(STATUS_FETCHING)
262-
response = self._wifi.requests.get(url, stream=True)
263+
response = self._wifi.requests.get(url, headers=headers, stream=True)
263264

265+
# we re-use this variable, now dealing with response headers
264266
headers = {}
265267
for title, content in response.headers.items():
266268
headers[title.lower()] = content

0 commit comments

Comments
 (0)