diff --git a/qiniu/utils.py b/qiniu/utils.py index 78eddcba..1b992fa9 100644 --- a/qiniu/utils.py +++ b/qiniu/utils.py @@ -151,4 +151,7 @@ def entry(bucket, key): Returns: 符合七牛API规格的数据格式 """ - return urlsafe_base64_encode('{0}:{1}'.format(bucket, key)) + if key is None: + return urlsafe_base64_encode('{0}'.format(bucket)) + else: + return urlsafe_base64_encode('{0}:{1}'.format(bucket, key)) diff --git a/test_qiniu.py b/test_qiniu.py index b8bf73e4..99655f69 100644 --- a/test_qiniu.py +++ b/test_qiniu.py @@ -125,6 +125,12 @@ def test_fetch(self): assert ret['key'] == 'fetch.html' assert ret['hash'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB' + def test_fetch_without_key(self): + ret, info = self.bucket.fetch('http://developer.qiniu.com/docs/v6/sdk/python-sdk.html', bucket_name) + print(info) + assert ret['key'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB' + assert ret['hash'] == 'FhwVT7vs6xqs1nu_vEdo_4x4qBMB' + def test_stat(self): ret, info = self.bucket.stat(bucket_name, 'python-sdk.html') print(info)