diff --git a/qiniu/http.py b/qiniu/http.py index 6d239808..86003dbc 100644 --- a/qiniu/http.py +++ b/qiniu/http.py @@ -185,12 +185,14 @@ def _get_with_qiniu_mac(url, params, auth): def _get_with_qiniu_mac_and_headers(url, params, auth, headers): + if _session is None: + _init() try: post_headers = _headers.copy() if headers is not None: for k, v in headers.items(): post_headers.update({k: v}) - r = requests.get( + r = _session.get( url, params=params, auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None, @@ -202,8 +204,10 @@ def _get_with_qiniu_mac_and_headers(url, params, auth, headers): def _delete_with_qiniu_mac(url, params, auth): + if _session is None: + _init() try: - r = requests.delete( + r = _session.delete( url, params=params, auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None, @@ -215,12 +219,14 @@ def _delete_with_qiniu_mac(url, params, auth): def _delete_with_qiniu_mac_and_headers(url, params, auth, headers): + if _session is None: + _init() try: post_headers = _headers.copy() if headers is not None: for k, v in headers.items(): post_headers.update({k: v}) - r = requests.delete( + r = _session.delete( url, params=params, auth=qiniu.auth.QiniuMacRequestsAuth(auth) if auth is not None else None, diff --git a/qiniu/region.py b/qiniu/region.py index 24c351d9..32f3e7e0 100644 --- a/qiniu/region.py +++ b/qiniu/region.py @@ -5,6 +5,7 @@ import requests from qiniu import compat from qiniu import utils +from qiniu import http UC_HOST = 'https://uc.qbox.me' # 获取空间信息Host @@ -201,7 +202,9 @@ def host_cache_to_file(self, home_dir): f.close() def bucket_hosts(self, ak, bucket): + if http._session is None: + http._init() url = "{0}/v1/query?ak={1}&bucket={2}".format(UC_HOST, ak, bucket) - ret = requests.get(url) + ret = http._session.get(url) data = compat.json.dumps(ret.json(), separators=(',', ':')) return data