In python3, the order of dict are not anymore constant, but can change between runs.
Florent Viard authored on 2017/05/30 18:33:50... | ... |
@@ -15,6 +15,7 @@ import base64 |
15 | 15 |
from . import Config |
16 | 16 |
from logging import debug |
17 | 17 |
from .Utils import encode_to_s3, time_to_epoch, deunicodise, decode_from_s3 |
18 |
+from .SortedDict import SortedDict |
|
18 | 19 |
|
19 | 20 |
import datetime |
20 | 21 |
try: |
... | ... |
@@ -227,10 +228,10 @@ def sign_request_v4(method='GET', host='', canonical_uri='/', params=None, |
227 | 227 |
|
228 | 228 |
signature = decode_from_s3(hmac.new(signing_key, encode_to_s3(string_to_sign), sha256).hexdigest()) |
229 | 229 |
authorization_header = algorithm + ' ' + 'Credential=' + access_key + '/' + credential_scope + ',' + 'SignedHeaders=' + signed_headers + ',' + 'Signature=' + signature |
230 |
- new_headers = dict(list(cur_headers.items()) + list({'x-amz-date':amzdate, |
|
231 |
- 'Authorization':authorization_header, |
|
232 |
- 'x-amz-content-sha256': payload_hash |
|
233 |
- }.items())) |
|
230 |
+ new_headers = SortedDict(cur_headers.items()) |
|
231 |
+ new_headers.update({'x-amz-date':amzdate, |
|
232 |
+ 'Authorization':authorization_header, |
|
233 |
+ 'x-amz-content-sha256': payload_hash}) |
|
234 | 234 |
debug("signature-v4 headers: %s" % new_headers) |
235 | 235 |
return new_headers |
236 | 236 |
__all__.append("sign_request_v4") |