From b78c1509f67fb76d17ac97193a2851d8d9e17f62 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Mon, 2 Mar 2020 15:06:25 -0800 Subject: [PATCH] try/except dialect detection --- jc/parsers/csv.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/jc/parsers/csv.py b/jc/parsers/csv.py index 793ac611..1c753954 100644 --- a/jc/parsers/csv.py +++ b/jc/parsers/csv.py @@ -3,7 +3,8 @@ Usage: specify --csv as the first argument if the piped input is coming from a csv file. - the csv parser will attempt to automatically detect the delimter character. + the csv parser will attempt to automatically detect the delimiter character. + if the delimiter cannot be detected it will default to comma. the first row of the file must be a header row. Compatibility: @@ -123,7 +124,12 @@ def parse(data, raw=False, quiet=False): cleandata = list(filter(None, cleandata)) if cleandata: - dialect = csv.Sniffer().sniff(data[:1024]) + dialect = None + try: + dialect = csv.Sniffer().sniff(data[:1024]) + except Exception: + pass + reader = csv.DictReader(cleandata, dialect=dialect) for row in reader: