Skip to content

Commit

Permalink
Merge pull request #2437 from obfusk/patch-19
Browse files Browse the repository at this point in the history
set urllib user-agent
  • Loading branch information
AndreMiras authored Mar 5, 2021
2 parents 9c4fff9 + 96639a0 commit 2bf2c6a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sh
import shutil
import fnmatch
import urllib.request
from urllib.request import urlretrieve
from os import listdir, unlink, environ, mkdir, curdir, walk
from sys import stdout
Expand All @@ -23,6 +24,11 @@
from pythonforandroid.util import load_source as import_recipe


url_opener = urllib.request.build_opener()
url_orig_headers = url_opener.addheaders
urllib.request.install_opener(url_opener)


class RecipeMeta(type):
def __new__(cls, name, bases, dct):
if name != 'Recipe':
Expand Down Expand Up @@ -206,6 +212,8 @@ def report_hook(index, blksize, size):
seconds = 1
while True:
try:
# jqueryui.com returns a 403 w/ the default user agent
url_opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urlretrieve(url, target, report_hook)
except OSError as e:
attempts += 1
Expand All @@ -215,6 +223,8 @@ def report_hook(index, blksize, size):
time.sleep(seconds)
seconds *= 2
continue
finally:
url_opener.addheaders = url_orig_headers
break
return target
elif parsed_url.scheme in ('git', 'git+file', 'git+ssh', 'git+http', 'git+https'):
Expand Down

0 comments on commit 2bf2c6a

Please sign in to comment.