Hostname will be `None` if the URL is invalid, so we need to trap it.