@@ -100,14 +100,14 @@ def __init__(self, Appid=None, Region=None, SecretId=None, SecretKey=None, Token
100100
101101 # 兼容(SecretId,SecretKey)以及(AccessId,AccessKey)
102102 if (SecretId and SecretKey ):
103- self ._secret_id = to_unicode (SecretId )
104- self ._secret_key = to_unicode (SecretKey )
103+ self ._secret_id = self . convert_secret_value (SecretId )
104+ self ._secret_key = self . convert_secret_value (SecretKey )
105105 elif (Secret_id and Secret_key ):
106- self ._secret_id = to_unicode (Secret_id )
107- self ._secret_key = to_unicode (Secret_key )
106+ self ._secret_id = self . convert_secret_value (Secret_id )
107+ self ._secret_key = self . convert_secret_value (Secret_key )
108108 elif (Access_id and Access_key ):
109- self ._secret_id = to_unicode (Access_id )
110- self ._secret_key = to_unicode (Access_key )
109+ self ._secret_id = self . convert_secret_value (Access_id )
110+ self ._secret_key = self . convert_secret_value (Access_key )
111111 else :
112112 raise CosClientError ('SecretId and SecretKey is Required!' )
113113
@@ -179,14 +179,22 @@ def set_credential(self, SecretId, SecretKey, Token=None):
179179 :param SecretKey(string): 秘钥SecretKey.
180180 :param Token(string): 临时秘钥使用的token.
181181 """
182- self ._secret_id = to_unicode (SecretId )
183- self ._secret_key = to_unicode (SecretKey )
184- self ._token = to_unicode (Token )
182+ self ._secret_id = self . convert_secret_value (SecretId )
183+ self ._secret_key = self . convert_secret_value (SecretKey )
184+ self ._token = self . convert_secret_value (Token )
185185
186186 def set_copy_part_threshold_size (self , size ):
187187 if size > 0 :
188188 self ._copy_part_threshold_size = size
189189
190+ def convert_secret_value (self , value ):
191+ value = to_unicode (value )
192+
193+ if value .endswith (' ' ) or value .startswith (' ' ):
194+ raise CosClientError ('secret_id and secret_key cannot contain spaces at the beginning and end' )
195+
196+ return value
197+
190198
191199class CosS3Client (object ):
192200 """cos客户端类,封装相应请求"""
0 commit comments