From 1aa77017d53e6f1c31a1a6734917598b66540293 Mon Sep 17 00:00:00 2001 From: Jakub Roztocil Date: Sat, 25 Jan 2014 14:56:56 +0100 Subject: [PATCH] Catch UnicodeDecodeError when embedding file via =@ or :=@. --- httpie/input.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/httpie/input.py b/httpie/input.py index 07c2d451..5c19c54e 100644 --- a/httpie/input.py +++ b/httpie/input.py @@ -608,7 +608,13 @@ def parse_items(items, data=None, headers=None, files=None, params=None): with open(os.path.expanduser(value), 'rb') as f: value = f.read().decode('utf8') except IOError as e: - raise ParseError('%s": %s' % (item.orig, e)) + raise ParseError('"%s": %s' % (item.orig, e)) + except UnicodeDecodeError: + raise ParseError( + '"%s": cannot embed the content of "%s",' + ' not a UTF8 or ASCII-encoded text file' + % (item.orig, item.value) + ) if item.sep in SEP_GROUP_RAW_JSON_ITEMS: try: