PeterDing / BaiduPCS-Py

BaiduPCS API & App 百度网盘客户端 和 API
MIT License
667 stars 108 forks source link

下载百度网盘某个文件夹出错,报System ERROR: HTTP Error 403: Forbidden #95

Closed youcanfind closed 1 year ago

youcanfind commented 1 year ago

WARNNING: Please to search the similar bugs, before you report a bug. Don't report a similar bug which existed. 注意:在你提交一份报告前,请先搜索是否存在类似的报告。请勿重复提交内容相同的报告。

Prerequisites / 报告前提 Before you report a bug, please let the bug to be reproduced at the latest verion of BaiduPCS-Py. 在你提交报告前,请在 BaiduPCS-Py 的最新版本上复现问题。

At sometimes, there are errors occured by an expired cookie. Before you commit the report, please to check whether cookies are expired. 有时一些错误是由于某个 cookie 超期导致的。在你提交报告前,请先检查你的 cookies 是否超期。

Describe the bug / 描述 bug A clear and concise description of what the bug is. 请清楚的描述你遇到的问题。 下载百度网盘中某个文件夹下的所有文件,在下载过程中报错System ERROR: HTTP Error 403: Forbidden后直接退出下载,再次尝试下载问题依旧。另外试着下载其它几个文件夹下文件,不出现该问题。 所用命令为:BaiduPCS-Py download /XXX -R -o local/disk/XXX/ -s 2

To Reproduce / 复现问题 Steps to reproduce the behavior:

  1. Do '...'
  2. Do '....'
  3. ...
  4. See error

按照下面的步骤可以复现问题:

  1. 做 '...'
  2. 做 '...'
  3. ...
  4. 问题出现

Screenshots / 问题截图 If applicable, add screenshots to help explain your problem.

Don't show BDUSS and cookies.

如果可能,请附加问题截图。

不要出现 BDUSScookies

Envrionment / 运行环境

Runing log / 运行日志 Please follow steps to paste the content of file ~/.baidupcs-py/running.log.

  1. Remove the file ~/.baidupcs-py/running.log if it exists.
  2. Run the command where the bug occurs with envrionment variable LOG_LEVEL=DEBUG. e.g. LOG_LEVEL=DEBUG BaiduPCS-Py upload /abc /
  3. Paste the content of file ~/.baidupcs-py/running.log after the bug occurs.

Don't show BDUSS and cookies.

请按照下面的步骤贴出运行日志 ~/.baidupcs-py/running.log 中的内容。

  1. 删除 ~/.baidupcs-py/running.log,如果存在。
  2. 在问题发生的命令前加入环境变量 LOG_LEVEL=DEBUG。 例如:LOG_LEVEL=DEBUG BaiduPCS-Py upload /abc /
  3. 在问题出现后,贴出 ~/.baidupcs-py/running.log 中的内容。

2022-08-26 15:03:02,371 | DEBUG | download: download: sifters: [], recursive: False, from_index: 0, downloader: Downloader.me, downloadparams: DownloadParams(chunk_size='52428800', concurrency=1, quiet=False), out_cmd: False, has encrypt_password: False 2022-08-26 15:03:02,371 | DEBUG | download: download: remotepaths should be uniq 1 == 1 XXX is ready existed. XXX is ready existed. 2022-08-26 15:03:04,575 | DEBUG | app: app: System Error: Traceback (most recent call last): File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/app/app.py", line 118, in wrap return func(*args, kwargs) File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/app/app.py", line 176, in wrap return func(*args, *kwargs) File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/app/app.py", line 1032, in download _download( File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/commands/download.py", line 414, in download download_dir( File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/commands/download.py", line 332, in download_dir download_file( File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/commands/download.py", line 299, in download_file dlink = api.download_link(remotepath) File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/baidupcs/api.py", line 543, in download_link return self._baidupcs.download_link(remotepath, pcs=pcs) File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/common/cache.py", line 46, in wrap val = func(args, kwargs) File "/home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/baidupcs/pcs.py", line 989, in download_link resp = urllib.request.urlopen(req) # type: ignore File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python3.8/urllib/request.py", line 531, in open response = meth(req, response) File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response response = self.parent.error( File "/usr/lib/python3.8/urllib/request.py", line 569, in error return self._call_chain(args) File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain result = func(args) File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: Forbidden

(v0.7.1) System ERROR: HTTP Error 403: Forbidden ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/app/app.py:118 in wrap │ │ │ │ 115 │ @wraps(func) │ │ 116 │ def wrap(*args, kwargs): │ │ 117 │ │ try: │ │ ❱ 118 │ │ │ return func(*args, *kwargs) │ │ 119 │ │ except BaiduPCSError as err: │ │ 120 │ │ │ _exit_progress_bar() │ │ 121 │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/app/app.py:176 in wrap │ │ │ │ 173 │ │ ctx = args[0] │ │ 174 │ │ user_ids = _user_ids(ctx) │ │ 175 │ │ if not user_ids: │ │ ❱ 176 │ │ │ return func(args, kwargs) │ │ 177 │ │ │ │ 178 │ │ am = ctx.obj.account_manager │ │ 179 │ │ for user_id in user_ids: │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/app/app.py:1032 in download │ │ │ │ 1029 │ else: │ │ 1030 │ │ encrypt_password = encrypt_password or _encrypt_password(ctx) │ │ 1031 │ │ │ ❱ 1032 │ _download( │ │ 1033 │ │ api, │ │ 1034 │ │ remotepaths, │ │ 1035 │ │ outdir, │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/commands/download.py:414 in download │ │ │ │ 411 │ │ │ ) │ │ 412 │ │ else: │ │ 413 │ │ │ _localdir = str(Path(localdir) / os.path.basename(rp)) │ │ ❱ 414 │ │ │ download_dir( │ │ 415 │ │ │ │ api, │ │ 416 │ │ │ │ rp, │ │ 417 │ │ │ │ _localdir, │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/commands/download.py:332 in download_dir │ │ │ │ 329 │ remotepaths = sift(remotepaths, sifters, recursive=recursive) │ │ 330 │ for rp in remotepaths[from_index:]: │ │ 331 │ │ if rp.is_file: │ │ ❱ 332 │ │ │ download_file( │ │ 333 │ │ │ │ api, │ │ 334 │ │ │ │ rp.path, │ │ 335 │ │ │ │ localdir, │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/commands/download.py:299 in │ │ download_file │ │ │ │ 296 │ │ print(f"[yellow]{localpath}[/yellow] is ready existed.") │ │ 297 │ │ return │ │ 298 │ │ │ ❱ 299 │ dlink = api.download_link(remotepath) │ │ 300 │ if not dlink: │ │ 301 │ │ display_blocked_remotepath(remotepath) │ │ 302 │ │ return │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/baidupcs/api.py:543 in download_link │ │ │ │ 540 │ │ │ and which has not limited threshold for a svip user. │ │ 541 │ │ """ │ │ 542 │ │ │ │ ❱ 543 │ │ return self._baidupcs.download_link(remotepath, pcs=pcs) │ │ 544 │ │ │ 545 │ def file_stream( │ │ 546 │ │ self, │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/common/cache.py:46 in wrap │ │ │ │ 43 │ │ │ val = _cache.get(key) │ │ 44 │ │ │ if val: │ │ 45 │ │ │ │ return val │ │ ❱ 46 │ │ │ val = func(*args, *kwargs) │ │ 47 │ │ │ _cache[key] = val │ │ 48 │ │ │ return val │ │ 49 │ │ │ │ /home/XXX/.local/lib/python3.8/site-packages/baidupcs_py/baidupcs/pcs.py:989 in download_link │ │ │ │ 986 │ │ │ headers = dict(PCS_HEADERS) │ │ 987 │ │ │ headers["Cookie"] = "; ".join([f"{k}={v}" for k, v in self.cookies.items()]) │ │ 988 │ │ │ req = urllib.request.Request(url + "?" + params_str, headers=headers, method │ │ ❱ 989 │ │ │ resp = urllib.request.urlopen(req) # type: ignore │ │ 990 │ │ │ │ │ 991 │ │ │ # Error: "user is not authorized" │ │ 992 │ │ │ # This error occurs when the method is called by too many times │ │ │ │ /usr/lib/python3.8/urllib/request.py:222 in urlopen │ │ │ │ 219 │ │ _opener = opener = build_opener() │ │ 220 │ else: │ │ 221 │ │ opener = _opener │ │ ❱ 222 │ return opener.open(url, data, timeout) │ │ 223 │ │ 224 def install_opener(opener): │ │ 225 │ global _opener │ │ │ │ /usr/lib/python3.8/urllib/request.py:531 in open │ │ │ │ 528 │ │ meth_name = protocol+"_response" │ │ 529 │ │ for processor in self.process_response.get(protocol, []): │ │ 530 │ │ │ meth = getattr(processor, meth_name) │ │ ❱ 531 │ │ │ response = meth(req, response) │ │ 532 │ │ │ │ 533 │ │ return response │ │ 534 │ │ │ │ /usr/lib/python3.8/urllib/request.py:640 in http_response │ │ │ │ 637 │ │ # According to RFC 2616, "2xx" code indicates that the client's │ │ 638 │ │ # request was successfully received, understood, and accepted. │ │ 639 │ │ if not (200 <= code < 300): │ │ ❱ 640 │ │ │ response = self.parent.error( │ │ 641 │ │ │ │ 'http', request, response, code, msg, hdrs) │ │ 642 │ │ │ │ 643 │ │ return response │ │ │ │ /usr/lib/python3.8/urllib/request.py:569 in error │ │ │ │ 566 │ │ │ │ 567 │ │ if http_err: │ │ 568 │ │ │ args = (dict, 'default', 'http_error_default') + orig_args │ │ ❱ 569 │ │ │ return self._call_chain(args) │ │ 570 │ │ 571 # XXX probably also want an abstract factory that knows when it makes │ │ 572 # sense to skip a superclass in favor of a subclass and when it might │ │ │ │ /usr/lib/python3.8/urllib/request.py:502 in _call_chain │ │ │ │ 499 │ │ handlers = chain.get(kind, ()) │ │ 500 │ │ for handler in handlers: │ │ 501 │ │ │ func = getattr(handler, meth_name) │ │ ❱ 502 │ │ │ result = func(*args) │ │ 503 │ │ │ if result is not None: │ │ 504 │ │ │ │ return result │ │ 505 │ │ │ │ /usr/lib/python3.8/urllib/request.py:649 in http_error_default │ │ │ │ 646 │ │ 647 class HTTPDefaultErrorHandler(BaseHandler): │ │ 648 │ def http_error_default(self, req, fp, code, msg, hdrs): │ │ ❱ 649 │ │ raise HTTPError(req.full_url, code, msg, hdrs, fp) │ │ 650 │ │ 651 class HTTPRedirectHandler(BaseHandler): │ │ 652 │ # maximum number of redirections to any single URL │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ HTTPError: HTTP Error 403: Forbidden 2022-08-26 15:03:05,124 | DEBUG | app: app: _teardown: start 2022-08-26 15:03:05,124 | DEBUG | app: app: _teardown: end

不要出现 BDUSScookies

Additional context / 补充内容 Add any other context about the problem here. 在这里增加补充内容。

PeterDing commented 1 year ago

这个文件夹下应该有被百度封了的文件。封了的文件不能下载,会报错。

zoubenjia commented 1 year ago

应该是urllib 里的异常没有handle。