Skip to content

Commit

Permalink
Better error msg if metadata contains a non us-ascii character
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vadmeste committed Jun 12, 2019
1 parent f3c0818 commit 2f8cd86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion minio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@
# if math.ceil returns an integer and devide two integers returns a float, calculate
# part size will cause errors, so make sure division integers returns a float.
from __future__ import division
import io

from __future__ import unicode_literals
# future_str is unicode or str in both Python 2 and 3
from builtins import str as future_str

import io
import collections
import base64
import hashlib
Expand Down Expand Up @@ -654,6 +658,16 @@ def optimal_part_info(length, part_size):
def amzprefix_user_metadata(metadata):
m = dict()
for k,v in metadata.items():
# Check if metadata value has US-ASCII encoding since it is
# the only one supported by HTTP headers. This will show a better
# exception message when users pass unsupported characters
# in metadata values.
try:
if isinstance(v, future_str):
v.encode('us-ascii')
except UnicodeEncodeError:
raise ValueError('Metadata supports only US-ASCII characters.')

if is_amz_header(k) or is_supported_header(k) or is_storageclass_header(k):
m[k] = v
else:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
]

requires = [
'future',
'urllib3',
'pytz',
'certifi',
Expand Down

0 comments on commit 2f8cd86

Please sign in to comment.