trevorhobenshield / amazon_photos

Amazon Photos API
https://pypi.org/project/amazon_photos
MIT License
44 stars 6 forks source link

.de support #10

Closed marktop closed 5 months ago

marktop commented 5 months ago

Hi, using cookies ubid-acbde and at-acbde with session-id from amazon.de, I'm able to use ap.usage(), ap.query() and ap.delete(), but not ap-upload():

python3 test.py
    type  billable_bytes  billable_count  total_bytes  total_count
0    doc               0               0            0            0
1  other               0               0            0            0
2  photo               0               0        35543            1
3  video               0               0            0            0
Checking for duplicate files: 100%|██████████████████████████████████████████████████| 29/29 [00:00<00:00, 4364.68it/s]
2024-01-12 22:37:26.289 [INFO] :: 0 Duplicate files found
2024-01-12 22:37:26.289 [INFO] :: 29 Unique files found
Uploading files:   0%|                                                                          | 0/29 [00:00<?, ?it/s]
2024-01-12 22:37:29.475 [ERROR] :: 401 {"logref":"0a7601b3-b598-477c-b689-044349b3c0ff","message":"No Auth Method Provided","code":""}

Many thanks having a look at this Mark

trevorhobenshield commented 5 months ago

Your cookies have likely expired. ap.usage() probably worked because it's read-only, but as soon as you perform any action that modifies state (upload, download, trash, etc.) Amazon may expire those cookies sooner, at least that's what I've noticed.

You can try logging out, logging back in, then copying the new cookies and trying again.

marktop commented 5 months ago

Hi Trevor, thank for your quick support!

Unfortunately no, I had already tried that - here again a log with fresh cookies: (ap.usage() - ap.delete(node_ids) - ap.upload('...') - delete worked, the upload didn't work again)

Are more cookies needed after all?

python3 test.py
    type  billable_bytes  billable_count  total_bytes  total_count
0    doc               0               0            0            0
1  other               0               0            0            0
2  photo               0               0        35543            1
3  video               0               0            0            0
Permanently deleting files: 100%|████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  5.53it/s]
Checking for duplicate files: 100%|██████████████████████████████████████████████████| 29/29 [00:00<00:00, 4776.36it/s]
2024-01-13 09:26:11.281 [INFO] :: 0 Duplicate files found
2024-01-13 09:26:11.282 [INFO] :: 29 Unique files found
Uploading files:   0%|                                                                          | 0/29 [00:00<?, ?it/s]
2024-01-13 09:26:12.253 [ERROR] :: 401 {"logref":"4c1020d0-58a9-4797-a72a-6154194846ef","message":"No Auth Method Provided","code":""}
marktop commented 5 months ago

I don't actually see any cookies in https://content-eu.drive.amazonaws.com/v2/upload?... Instead a header X-Amz-Access-Token!

trevorhobenshield commented 5 months ago

It should be fixed now, let me know if there are any other issues.

The problem was that I had hard-coded that upload URL to the default na variant: https://content-na.drive.amazonaws.com/cdproxy/nodes.

OncleTif commented 5 months ago

I had the same problem with a french account, with the version 0.0.96 I had to replace eu line from determine_cdproxy to 'https://content-eu.drive.amazonaws.com/cdproxy/nodes' (always .com) to make it work, do you want a PR?

trevorhobenshield commented 5 months ago

Interesting @OncleTif, thanks for noting this! Updates have been made, as of v0.0.97 everything should work as expected.

Alternatively, you can also use the override parameter if Amazon decides to change things again.

E.g.


ap = AmazonPhotos(
    cookies={
        ...
    },
    db_path='ap.parquet',
    dtype_backend='pyarrow',
    engine='pyarrow',
    cdproxy_override='https://content-eu.drive.amazonaws.com/cdproxy/nodes'
)
marktop commented 5 months ago

Great job, thanks for the quick adaption! Works now: Uploading files: 100%|█████████████████████████████████████████████████████████████████| 30/30 [00:12<00:00, 2.41it/s] Have a nice Sunday!