je remarquai que demander une URL invalide requests.get(invalid_url)
jette les exceptions suivantes:Est-il précis d'utiliser `requests` pour vérifier si un nom de domaine est enregistré?
Traceback (most recent call last):
File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
During handling of the above exception, another exception occurred:
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 607, in urlopen
raise MaxRetryError(self, url, e)
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='sparkandshine.me', port=80): Max retries exceeded with url:/(Caused by <class 'socket.gaierror'>: [Errno -2] Name or service not known)
During handling of the above exception, another exception occurred:
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 378, in send
raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='sparkandshine.me', port=80): Max retries exceeded with url:/(Caused by <class 'socket.gaierror'>: [Errno -2] Name or service not known)
Est-il exact de déterminer si un nom de domaine est enregistré ou non en attrapant ces exceptions? Voici le code source:
#!/usr/bin/env python3
import http
import urllib3
import requests
url = 'http://example.com'
try :
r = requests.get(url)
except (http.client.HTTPException, urllib3.exceptions.MaxRetryError, requests.exceptions.ConnectionError):
print(url) #this domain name is not registered?
La meilleure façon de vérifier la disponibilité d'un domaine est de savoir, je suppose, plutôt que d'essayer simplement de résoudre ce nom. –
@CongMa Je viens juste de savoir qu'il existe un module python nommé [pywhois] (https://bitbucket.org/richardpenman/pywhois). Pour l'installer, installez python-whois. – SparkAndShine
Aucun module existant comme je le sais. Vous feriez mieux d'utiliser 'requests' pour rechercher le domaine sur' godaddy' – LittleQ