web-dev-qa-db-fra.com

urllib HTTPS request: <urlopen error unknown url type: https>

J'ai un script sur python3.4 et cela s'est bien passé jusqu'à ce que le site Web sur lequel je télécharge le fichier décide d'utiliser https et maintenant je reçois une erreur mais je ne peux pas comprendre comment je peux récupérer le fichier.

Mon script importe la bibliothèque suivante et utilise l'urlretrive pour obtenir le fichier précédemment. Puisqu'il est maintenant transmis à https avec la redirection 302. Je reçois une erreur.

import urllib
import urllib.request

urllib.request.urlretrieve("http://wordpress.org/latest.tar.gz", "/thefile.gz")

Mon erreur: -

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/urllib/request.py", line 178, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/usr/local/lib/python3.4/urllib/request.py", line 153, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.4/urllib/request.py", line 461, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.4/urllib/request.py", line 571, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/lib/python3.4/urllib/request.py", line 493, in error
    result = self._call_chain(*args)
  File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.4/urllib/request.py", line 676, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/local/lib/python3.4/urllib/request.py", line 455, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.4/urllib/request.py", line 478, in _open
    'unknown_open', req)
  File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.4/urllib/request.py", line 1257, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>
12
Adi Wong

Votre installation Python ou système d'exploitation est probablement en panne.

Python ne prend en charge HTTPS que s'il a été compilé avec la prise en charge HTTPS. Cependant, cela devrait être la valeur par défaut pour toutes les installations saines.

HTTPS support is only available if the socket module was compiled with SSL support.

https://docs.python.org/3/library/http.client.html

Veuillez préciser comment vous avez installé Python. Python sont disponibles sur python.org

20
Mikko Ohtamaa

J'ai eu le même problème avec Anaconda mais après avoir installé le paquet OpenSSL, cela fonctionne bien.

conda install -c anaconda openssl
0