Skip to content

Commit

Permalink
add proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
dt3310321 committed Aug 23, 2019
1 parent a5ed160 commit 51497be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions qcloud_cos/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CosConfig(object):
"""config类,保存用户相关信息"""
def __init__(self, Appid=None, Region=None, SecretId=None, SecretKey=None, Token=None, Scheme=None, Timeout=None,
Access_id=None, Access_key=None, Secret_id=None, Secret_key=None,
Endpoint=None, IP=None, Port=None, Anonymous=None, UA=None):
Endpoint=None, IP=None, Port=None, Anonymous=None, UA=None, Proxies=None):
"""初始化,保存用户的信息
:param Appid(string): 用户APPID.
Expand All @@ -50,6 +50,7 @@ def __init__(self, Appid=None, Region=None, SecretId=None, SecretKey=None, Token
:param Port(int): 访问COS的port
:param Anonymous(bool): 是否使用匿名访问COS
:param UA(string): 使用自定义的UA来访问COS
:param Proxies(dict): 使用代理来访问COS
"""
self._appid = to_unicode(Appid)
self._token = to_unicode(Token)
Expand All @@ -60,6 +61,7 @@ def __init__(self, Appid=None, Region=None, SecretId=None, SecretKey=None, Token
self._port = Port
self._anonymous = Anonymous
self._ua = UA
self._proxies = Proxies

if Scheme is None:
Scheme = u'https'
Expand Down Expand Up @@ -217,15 +219,15 @@ def send_request(self, method, url, bucket, timeout=30, **kwargs):
for j in range(self._retry + 1):
try:
if method == 'POST':
res = self._session.post(url, timeout=timeout, **kwargs)
res = self._session.post(url, timeout=timeout, proxies=self._conf.proxies, **kwargs)
elif method == 'GET':
res = self._session.get(url, timeout=timeout, **kwargs)
res = self._session.get(url, timeout=timeout, proxies=self._conf.proxies, **kwargs)
elif method == 'PUT':
res = self._session.put(url, timeout=timeout, **kwargs)
res = self._session.put(url, timeout=timeout, proxies=self._conf.proxies, **kwargs)
elif method == 'DELETE':
res = self._session.delete(url, timeout=timeout, **kwargs)
res = self._session.delete(url, timeout=timeout, proxies=self._conf.proxies, **kwargs)
elif method == 'HEAD':
res = self._session.head(url, timeout=timeout, **kwargs)
res = self._session.head(url, timeout=timeout, proxies=self._conf.proxies, **kwargs)
if res.status_code < 400: # 2xx和3xx都认为是成功的
return res
except Exception as e: # 捕获requests抛出的如timeout等客户端错误,转化为客户端错误
Expand Down
2 changes: 1 addition & 1 deletion qcloud_cos/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

__version__ = '5.1.7.3'
__version__ = '5.1.7.4'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def long_description():

setup(
name='cos-python-sdk-v5',
version='1.7.3',
version='1.7.4',
url='https://www.qcloud.com/',
license='MIT',
author='tiedu, lewzylu, channingliu',
Expand Down

0 comments on commit 51497be

Please sign in to comment.