Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

替换为使用公共的_session,以便支持代理 #429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions qiniu/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion qiniu/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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