Skip to content

Commit

Permalink
Merge pull request #83 from xzzpig/master
Browse files Browse the repository at this point in the history
修复上传下载失败的问题
  • Loading branch information
ly0 committed Aug 26, 2018
2 parents f80b576 + 6f8fc22 commit 144fc89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions baidupcsapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ def check_login(func):
def wrapper(*args, **kwargs):
ret = func(*args, **kwargs)
if type(ret) == requests.Response:
# 检测结果是否为JSON
if ret.content[0]!=b'{' and ret.content[0]!=b'[':
return ret
try:
foo = json.loads(ret.content.decode('utf-8'))
if 'errno' in foo and foo['errno'] == -6:
Expand Down Expand Up @@ -552,7 +555,7 @@ def quota(self, **kwargs):
"""
return self._request('quota', **kwargs)

def upload(self, dest_dir, file_handler, filename, ondup="newcopy", callback=None, **kwargs):
def upload(self, dest_dir, file_handler, filename, callback=None, **kwargs):
"""上传单个文件(<2G).
| 百度PCS服务目前支持最大2G的单个文件上传。
Expand All @@ -578,11 +581,6 @@ def upload(self, dest_dir, file_handler, filename, ondup="newcopy", callback=Non
:param filename:
:param ondup: (可选)
* 'overwrite':表示覆盖同名文件;
* 'newcopy':表示生成文件副本并进行重命名,命名规则为“
文件名_日期.后缀”。
:return: requests.Response 对象
.. note::
Expand All @@ -593,9 +591,7 @@ def upload(self, dest_dir, file_handler, filename, ondup="newcopy", callback=Non
"""

params = {
'dest_dir': dest_dir,
'ondup': ondup,
'filename': filename
'path':str(dest_dir)+"/"+str(filename)
}

tmp_filename = ''.join(random.sample(string.ascii_letters, 10))
Expand Down
2 changes: 1 addition & 1 deletion examples/remote_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self,
'timeout': 60,
}

def ruokuai_captcha_handler(s, params, image_url):
def ruokuai_captcha_handler(self, params, image_url):
"""
若快自动识别验证码, 文档见: http://wiki.ruokuai.com/
"""
Expand Down

0 comments on commit 144fc89

Please sign in to comment.