logger.warning("Failed fetching url='%s': response.ok='%s',response.status_code=%d,response.content()=%d - EXIT!", url, response.ok, response.status_code, len(response.text))
return 1
- reader = csv.DictReader(response.content.decode("utf-8").splitlines(), dialect="unix")
+ lines = response.content.decode("utf-8").splitlines()
+
+ logger.debug("Reading %d lines, dialect=unix ...", len(lines))
+ reader = csv.DictReader(lines, dialect="unix")
logger.debug("reader[]='%s'", type(reader))
if reader is None:
requests.exceptions.ContentDecodingError,
requests.exceptions.InvalidSchema,
requests.exceptions.InvalidURL,
+ requests.exceptions.SSLError,
requests.exceptions.Timeout,
eventlet.timeout.Timeout,
requests.exceptions.TooManyRedirects,
UnicodeDecodeError,
UnicodeEncodeError,
- urllib3.exceptions.LocationParseError
+ urllib3.exceptions.LocationParseError,
+ urllib3.util.ssl_match_hostname.CertificateError,
)
logging.basicConfig(level=logging.INFO)
logger.debug("response[]='%s' - EXIT!", type(response))
return response
-def fetch_url(url: str, headers: dict, timeout: tuple) -> requests.models.Response:
- logger.debug("url='%s',headers()=%d,timeout(%d)='%s' - CALLED!", url, len(headers), len(timeout), timeout)
+def fetch_url(url: str, headers: dict, timeout: tuple, allow_redirects: bool = True) -> requests.models.Response:
+ logger.debug("url='%s',headers()=%d,timeout(%d)='%s',allow_redirects='%s' - CALLED!", url, len(headers), len(timeout), timeout, allow_redirects)
if not isinstance(url, str):
raise ValueError(f"Parameter url[]='{type(url)}' is not of type 'str'")
raise ValueError(f"Parameter headers[]='{type(headers)}' is not of type 'dict'")
elif not isinstance(timeout, tuple):
raise ValueError(f"Parameter timeout[]='{type(timeout)}' is not of type 'tuple'")
+ elif not isinstance(allow_redirects, bool):
+ raise ValueError(f"Parameter allow_redirects[]='{type(allow_redirects)}' is not of type 'bool'")
logger.debug("Parsing url='%s' ...", url)
components = urlparse(url)
components.netloc.split(":")[0],
f"{components.path}?{components.query}",
headers=headers,
- timeout=timeout
+ timeout=timeout,
+ allow_redirects=allow_redirects
)
else:
logger.debug("Fetching path='%s' from netloc='%s' ...", components.path, components.netloc)
components.netloc.split(":")[0],
components.path if isinstance(components.path, str) and components.path != '' else '/',
headers=headers,
- timeout=timeout
+ timeout=timeout,
+ allow_redirects=allow_redirects
)
logger.debug("response[]='%s' - EXIT!", type(response))