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

修复2021.2.28开始无法上传文件的问题 #52

Merged
merged 1 commit into from
Mar 2, 2021

Conversation

fzls
Copy link
Contributor

@fzls fzls commented Feb 27, 2021

从2021.2.28开始,调用upload_file接口后,会上传失败,且若设定了uploaded_handler,会抛出异常:KeyError: 'text'

原因分析:

应该是蓝奏云开始校验headers中的Referer,原有的https://pan.lanzous.com会导致上传失败

解决办法:

Referer修改为https://pc.woozooo.com/mydisk.php

测试脚本:

前置要求

  1. 需修改cookie为实际值才可以运行
  2. 在测试目录创建非空文件 测试上传接口.txt
from lanzou.api import LanZouCloud

lanzou_cookie = {
    "ylogin": "这里填写你的账号的该cookie",
    "phpdisk_info": "这里填写你的账号的该cookie",
}


def test():
    lzy = LanZouCloud()
    if lzy.login_by_cookie(lanzou_cookie) != LanZouCloud.SUCCESS:
        print("登录失败")
        return

    retCode = lzy.upload_file("./测试上传接口.txt", -1, callback=None, uploaded_handler=lambda fid, is_file: print(f"上传结果为 fid={fid}, is_file={is_file}"))
    if retCode != LanZouCloud.SUCCESS:
        print(f"上传失败,错误码为{retCode}")
        return

    print("上传成功")


if __name__ == '__main__':
    test()

当前运行结果

Traceback (most recent call last):
  File "D:test/test.py", line 24, in <module>
    test()
  File "D:test/test.py", line 15, in test
    retCode = lzy.upload_file("./测试上传接口.txt", -1, callback=None, uploaded_handler=lambda fid, is_file: print(f"上传结果为 fid={fid}, is_file={is_file}"))
  File "D:test\.venv\lib\site-packages\lanzou\api\core.py", line 870, in upload_file
    return self._upload_small_file(file_path, folder_id, callback=callback, uploaded_handler=uploaded_handler)
  File "D:test\.venv\lib\site-packages\lanzou\api\core.py", line 776, in _upload_small_file
    file_id = int(result["text"][0]["id"])
KeyError: 'text'

修改后运行结果

上传结果为 fid=39130827, is_file=True
上传成功

@fzls fzls changed the title 修复2021.2.28开始无法上传文件的问题 修复2021.2.28开始无法上传文件的问题 fix #51 Feb 27, 2021
@fzls fzls changed the title 修复2021.2.28开始无法上传文件的问题 fix #51 修复2021.2.28开始无法上传文件的问题 Feb 27, 2021
Copy link
Owner

@zaxtyson zaxtyson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

的确是这样😁, 官方又在搞事情

@zaxtyson zaxtyson merged commit bad5ca8 into zaxtyson:master Mar 2, 2021
@zaxtyson zaxtyson added the bug Something isn't working label Mar 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants