diff --git a/django/core/management/templates.py b/django/core/management/templates.py
a
|
b
|
|
6 | 6 | import stat |
7 | 7 | import tempfile |
8 | 8 | from importlib import import_module |
9 | | from urllib.request import urlretrieve |
| 9 | from urllib.request import Request, urlopen |
10 | 10 | |
11 | 11 | import django |
12 | 12 | from django.conf import settings |
… |
… |
|
262 | 262 | if self.verbosity >= 2: |
263 | 263 | self.stdout.write('Downloading %s' % display_url) |
264 | 264 | try: |
265 | | the_path, info = urlretrieve(url, os.path.join(tempdir, filename)) |
| 265 | response = urlopen(Request(url, headers={'User-Agent': f'Django/{django.getversion()}'})) |
| 266 | the_path = os.path.join(tempdir, filename) |
| 267 | with open(the_path, 'wb') as f: |
| 268 | f.write(response.read()) |
| 269 | |
266 | 270 | except OSError as e: |
267 | 271 | raise CommandError("couldn't download URL %s to %s: %s" % |
268 | 272 | (url, filename, e)) |
… |
… |
|
270 | 274 | used_name = the_path.split('/')[-1] |
271 | 275 | |
272 | 276 | # Trying to get better name from response headers |
273 | | content_disposition = info.get('content-disposition') |
| 277 | content_disposition = response.info.getheader('content-disposition') |
274 | 278 | if content_disposition: |
275 | 279 | _, params = cgi.parse_header(content_disposition) |
276 | 280 | guessed_filename = params.get('filename') or used_name |
… |
… |
|
279 | 283 | |
280 | 284 | # Falling back to content type guessing |
281 | 285 | ext = self.splitext(guessed_filename)[1] |
282 | | content_type = info.get('content-type') |
| 286 | content_type = response.info.getheader('content-type') |
283 | 287 | if not ext and content_type: |
284 | 288 | ext = mimetypes.guess_extension(content_type) |
285 | 289 | if ext: |