Skip to content
This repository has been archived by the owner on Sep 10, 2020. It is now read-only.

Commit

Permalink
[utils] Add error handling in csvfile validation
Browse files Browse the repository at this point in the history
Fixes #251

Remove extra whitespace
  • Loading branch information
Aviral14 committed Nov 19, 2019
1 parent 3b745b5 commit 782122a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion django_freeradius/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def find_available_username(username, users_list, prefix=False):

def validate_csvfile(csvfile):
csv_data = csvfile.read()
csv_data = csv_data.decode('utf-8') if isinstance(csv_data, bytes) else csv_data
try:
csv_data = csv_data.decode('utf-8') if isinstance(csv_data, bytes) else csv_data
except UnicodeDecodeError:
raise ValidationError("Incorrect file format has been uploaded. Please Try Again!")
reader = csv.reader(StringIO(csv_data), delimiter=',')
error_message = "The CSV contains a line with invalid data,\
line number {} triggered the following error: {}"
Expand Down

0 comments on commit 782122a

Please sign in to comment.