foyoux / aligo

🔥简单、易用、可扩展的阿里云盘 API 接口库🚀
GNU General Public License v3.0
849 stars 156 forks source link

无效下载链接或链接已过期 {resp.url} #26

Closed JingMatrix closed 2 years ago

JingMatrix commented 2 years ago

操作系统信息

The outout of uname -a:

Linux Matrix.xyz 5.15.0-35-generic #36-Ubuntu SMP Sat May 21 02:24:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

错误描述

无法直接下载分享文件,即使转存之后也不行。 Traceback:

Traceback (most recent call last):
  File "/home/jing/Documents/Code/Shell/scripts/aliyun-share", line 77, in <module>
    ali.download_file(download_path, download_url)
  File "/home/jing/.local/lib/python3.10/site-packages/aligo/apis/Download.py", line 160, in download_file
    return self._core_download_file(file_path, url)
  File "/home/jing/.local/lib/python3.10/site-packages/aligo/core/Download.py", line 96, in _core_download_file
    raise ValueError(f'无效下载链接或链接已过期 {resp.url}')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/jing/Documents/Code/Shell/scripts/aliyun-share", line 85, in <module>
    ali.download_file(file_id=file_id, local_folder="/tmp")
  File "/home/jing/.local/lib/python3.10/site-packages/aligo/apis/Download.py", line 160, in download_file
    return self._core_download_file(file_path, url)
  File "/home/jing/.local/lib/python3.10/site-packages/aligo/core/Download.py", line 96, in _core_download_file
    raise ValueError(f'无效下载链接或链接已过期 {resp.url}')

我的代码片段如下:

download_url = ali.get_share_link_download_url(
    share_id=share_id, share_token=share_token,
    file_id=file_id).download_url
if download_path == '':
    download_path = '/tmp/' + ali.get_share_file(
        share_id=share_id,
        share_token=share_token.share_token,
        file_id=file_id).name
try:
    ali.download_file(download_path, download_url)
except ValueError:
    file_id = ali.share_file_saveto_drive(
        share_id=share_id,
        share_token=share_token,
        file_id=file_id).file_id
    try:
        ali.download_file(file_id=file_id, local_folder="/tmp")
    finally:
        ali.move_file_to_trash(file_id=file_id)
JingMatrix commented 2 years ago

使用 aria2c 下载正常,由此可见是代码问题。

lemisky commented 2 years ago

老铁,可能代码不对,用关键字参数

JingMatrix commented 2 years ago

不是的,是代码的 _core_download_file 实现有问题。使用 'aria2c' 没有问题的话,说明代码运行到 https://github.com/foyoux/aligo/blob/main/aligo/core/Download.py#L77 是没有问题的。 而且我自己的代码在两个月前是可以运行的,我感觉是 ali 的 http 下载改变什么吧。 有没有可能 ali 突然不支持分段下载了? https://github.com/foyoux/aligo/blob/main/aligo/core/Download.py#L95

lemisky commented 2 years ago

代码之前OK,现在不行了,对吗?

lemisky commented 2 years ago

前几次改过http访问的代码,可能是那次改坏的,晚上处理。

JingMatrix commented 2 years ago

是的,之前我都不需要加 try .. catch 的,今天还以为 ali 不支持直接下载了,所以加了个转存代码。

lemisky commented 2 years ago

已修复此问题