Skip to content

Commit 984a1ce

Browse files
committed
Fix up hmac param can not be unicode
1 parent 0e49c2c commit 984a1ce

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

qcloud_cos/cos_auth.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,22 @@ def filter_headers(data):
2424
return headers
2525

2626

27+
def to_string(data):
28+
"""转换unicode为string.
29+
30+
:param data(unicode|string): 待转换的unicode|string.
31+
:return(string): 转换后的string.
32+
"""
33+
if isinstance(data, unicode):
34+
return data.encode('utf8')
35+
return data
36+
37+
2738
class CosS3Auth(AuthBase):
2839

29-
def __init__(self, access_id, secret_key, key='', params={}, expire=10000):
30-
self._access_id = access_id
31-
self._secret_key = secret_key
40+
def __init__(self, secret_id, secret_key, key='', params={}, expire=10000):
41+
self._secret_id = to_string(secret_id)
42+
self._secret_key = to_string(secret_key)
3243
self._expire = expire
3344
self._params = params
3445
if key:
@@ -67,7 +78,7 @@ def __call__(self, r):
6778
sign_tpl = "q-sign-algorithm=sha1&q-ak={ak}&q-sign-time={sign_time}&q-key-time={key_time}&q-header-list={headers}&q-url-param-list={params}&q-signature={sign}"
6879

6980
r.headers['Authorization'] = sign_tpl.format(
70-
ak=self._access_id,
81+
ak=self._secret_id,
7182
sign_time=sign_time,
7283
key_time=sign_time,
7384
params=';'.join(sorted(map(lambda k: k.lower(), uri_params.keys()))),

0 commit comments

Comments
 (0)