Skip to content

Commit e246926

Browse files
vadmestekannappanr
authored andcommitted
Better error msg if metadata contains a non us-ascii character (#770)
Pass 'é' or other non us-ascii character as a metadata value shows a signature mismatch error. The reason is that S3 server ignores those characters in headers since only US-ASCII characters are supported in HTTP headers. This commit shows an exception so users can understand better what's going on.
1 parent f3c0818 commit e246926

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

minio/helpers.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
# if math.ceil returns an integer and devide two integers returns a float, calculate
2929
# part size will cause errors, so make sure division integers returns a float.
3030
from __future__ import division
31-
import io
3231

32+
from __future__ import unicode_literals
33+
# future_str is unicode or str in both Python 2 and 3
34+
from builtins import str as future_str
35+
36+
import io
3337
import collections
3438
import base64
3539
import hashlib
@@ -654,6 +658,16 @@ def optimal_part_info(length, part_size):
654658
def amzprefix_user_metadata(metadata):
655659
m = dict()
656660
for k,v in metadata.items():
661+
# Check if metadata value has US-ASCII encoding since it is
662+
# the only one supported by HTTP headers. This will show a better
663+
# exception message when users pass unsupported characters
664+
# in metadata values.
665+
try:
666+
if isinstance(v, future_str):
667+
v.encode('us-ascii')
668+
except UnicodeEncodeError:
669+
raise ValueError('Metadata supports only US-ASCII characters.')
670+
657671
if is_amz_header(k) or is_supported_header(k) or is_storageclass_header(k):
658672
m[k] = v
659673
else:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
]
4141

4242
requires = [
43+
'future',
4344
'urllib3',
4445
'pytz',
4546
'certifi',

0 commit comments

Comments
 (0)