teticio / kindle2pdf

Convert owned Kindle books to PDF without needing a device. Good for viewing on a ReMarkable.
BSD 3-Clause "New" or "Revised" License
18 stars 1 forks source link

No access to browser cookies #7

Open JanOwiesniak opened 2 days ago

JanOwiesniak commented 2 days ago

System

macOS Version 13.6 (22G120) Chrome Version 129.0.6668.101

Issue

I logged in with my Amazon credentials on https://read.amazon.com but it seems like requests.utils.dict_from_cookiejar(cookies) returns an empty array.

chrome-cookies

run pip package

kindle2pdf B084514TDV                           
Traceback (most recent call last):
  File "/opt/homebrew/bin/kindle2pdf", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 502, in main
    kindle2pdf = Kindle2PDF(
                 ^^^^^^^^^^^
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 89, in __init__
    self.session = self.start_reading_session()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 102, in start_reading_session
    "x-amzn-sessionid": requests.utils.dict_from_cookiejar(cookies)[
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'session-id'

ran source code

python3 -m src.kindle2pdf B084514TDV            
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 518, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 502, in main
    kindle2pdf = Kindle2PDF(
                 ^^^^^^^^^^^
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 89, in __init__
    self.session = self.start_reading_session()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jan/Code/kindle2pdf/src/kindle2pdf.py", line 102, in start_reading_session
    "x-amzn-sessionid": requests.utils.dict_from_cookiejar(cookies)[
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'session-id'
teticio commented 2 days ago

Thanks for the detailed report. It does seem as though browser-cookie3 is not working. It would be great if you could try to debug it further or check the issues at https://github.com/borisbabic/browser_cookie3/issues, but there isn't much I can do as it works for me (on Mac, Linux and Windows). A minimal test code would be

from browser_cookie3 import chrome
print(chrome(domain_name="amazon.com"))
# Obviously don't post the results from this anywhere

Alternatively, just to get it working for yourself you could at line 100 to kindle2pdf.py

cookies["sesion-id"] = "..." # Get this from the Inspector in Chrome

I'm thinking of adding a manual way to set the cookie for these cases.

teticio commented 2 days ago

Although now I think of it, there may be other cookies required. Will check.

teticio commented 2 days ago

Nah, sorry, a boringly large number of cookies are required.