I am new to this so please help me. I am using urllib.request to open and reading webpages. Can someone tell me how can my code handle redirects, timeouts, badly formed URLs? 
I have sort of found a way for timeouts, I am not sure if it is correct though. Is it? All opinions are welcomed! Here it is:
from socket import timeout
import urllib.request
try:
            text = urllib.request.urlopen(url, timeout=10).read().decode('utf-8')
except (HTTPError, URLError) as error:
            logging.error('Data of %s not retrieved because %s\nURL: %s', name, error, url)
except timeout:
            logging.error('socket timed out - URL %s', url)
Please help me as I am new to this. Thanks!
 
    