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

python kindle.py --pdoc --mode sel --cn --cookie ${cookie} ${csrf}报错 #139

Open
zhmfalove opened this issue Jul 19, 2023 · 8 comments
Open

Comments

@zhmfalove
Copy link

Error: CSRF_VALIDATION_FAILED, please visit https://www.amazon.cn/hz/mycd/myx#/home/content/booksAll to revoke the csrftoken and cookie

事实上此时的cookie和csrf能通过gui版本正确获取电子书,
但是运行“python kindle.py --pdoc --mode sel --cn --cookie ${cookie} ${csrf}” 报以上错误

@yihong0618
Copy link
Owner

csrf token 放在第一个位置

@zhmfalove
Copy link
Author

zhmfalove commented Jul 19, 2023

@yihong0618

还是不行,现在是这样运行的“python kindle.py --cn ${csrf} --cookie ${cookie} --pdoc --mode sel ” 还是同样的错误

@yihong0618
Copy link
Owner

@yihong0618

还是不行,现在是这样运行的“python kindle.py --cn ${csrf} --cookie ${cookie} --pdoc --mode sel ” 还是同样的错误

是这样,gui 能运行,cli 理论应该也可以,因为两个是一个原理。。。你看看,cookie 用单引号包裹?

@zhmfalove
Copy link
Author

@yihong0618
还是不行,我把代码用jupyter notebook运行,运行代码,跳转到亚马逊kindle的所有内容界面,然后就报错,同样的是当时这个错误,不知道这个类的初始化值是不是错了。
微信截图_20230719164014

@yihong0618
Copy link
Owner

不是,如果不行的话,GUI 好用你可以先用 GUI, 我有时间会研究下为什么,但现在比较忙

@huataihuang
Copy link

@yihong0618
还是不行,我把代码用jupyter notebook运行,运行代码,跳转到亚马逊kindle的所有内容界面,然后就报错,同样的是当时这个错误,不知道这个类的初始化值是不是错了。
微信截图_20230719164014

我遇到的问题报错和你类似,也是 在 device = self.find_device() 这几个函数报错,也就是获取默认设备报错。我使用了默认cookie自动获取的方式:

csrfToken="XXXXXXXX"
device_sn="YYYYYY"

python3 kindle.py --device_sn ${device_sn} --dedrm --cn ${csrfToken}

出现报错

Traceback (most recent call last):
  File "/Users/huataihuang/docs/github.com/yihong0618/Kindle_download_helper/kindle.py", line 5, in <module>
    main()
  File "/Users/huataihuang/docs/github.com/yihong0618/Kindle_download_helper/kindle_download_helper/cli.py", line 318, in main
    kindle.download_books(
  File "/Users/huataihuang/docs/github.com/yihong0618/Kindle_download_helper/kindle_download_helper/kindle.py", line 529, in download_books
    device = self.find_device()
             ^^^^^^^^^^^^^^^^^^
  File "/Users/huataihuang/docs/github.com/yihong0618/Kindle_download_helper/kindle_download_helper/kindle.py", line 130, in find_device
    devices = self.get_devices()
              ^^^^^^^^^^^^^^^^^^
  File "/Users/huataihuang/docs/github.com/yihong0618/Kindle_download_helper/kindle_download_helper/kindle.py", line 224, in get_devices
    r.raise_for_status()
  File "/Users/huataihuang/venv3/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 503 Server Error: Service Unavailable for url: https://www.amazon.cn/hz/mycd/ajax

我理解在 kindle_download_helper/kindle.py 是从 cookie 中获取设备,所以怀疑是自动获取cookie的问题,所以按照帮助,在浏览器中F12找出cookie,带着 cookie 执行就成功了

cookie="ZZZ"
csrfToken="XXXXXXXX"
device_sn="YYYYYY"

python3 kindle.py --device_sn ${device_sn} --dedrm --cn --cookie ${cookie} ${csrfToken}

忽略 --dedrm 这个执行不成功

@yihong0618
Copy link
Owner

@huataihuang 感谢,我们研究下,如果有兴趣,PR welcome 哈

@zhmfalove
Copy link
Author

@huataihuang @yihong0618 问题已经解决,疑似python版本问题,升级python 3.11.4 就没有这个问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants