Skip to content

Commit b9d67c9

Browse files
committed
Use 'urllib2' for retrieving mbed library
For some reason when using 'urllib' in my environment (which includes a Zscaler network proxy) 'urllib.urlretrieve()' does not work ending up with an error message "301 Moved Permanently". Python library 'urllib2' doesn't have this issue but does not provide method 'urlretrieve()', so a little workaround is required.
1 parent ad45de3 commit b9d67c9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mbed/mbed.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import errno
3030
from itertools import chain, izip, repeat
3131
from urlparse import urlparse
32-
import urllib
32+
import urllib2
3333
import zipfile
3434
import argparse
3535

@@ -281,7 +281,10 @@ def fetch_rev(url, rev):
281281
try:
282282
if not os.path.exists(tmp_file):
283283
action("Downloading mbed library build \"%s\" (might take a minute)" % rev)
284-
urllib.urlretrieve(url, tmp_file)
284+
outfd = open(tmp_file, 'wb')
285+
inurl = urllib2.urlopen(url)
286+
outfd.write(inurl.read())
287+
outfd.close()
285288
except:
286289
if os.path.isfile(tmp_file):
287290
os.remove(tmp_file)
@@ -2427,4 +2430,4 @@ def main():
24272430

24282431

24292432
if __name__ == "__main__":
2430-
main()
2433+
main()

0 commit comments

Comments
 (0)