trevorhobenshield / amazon_photos

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

AttributeError: 'NoneType' object has no attribute 'json' #3

Closed ryanshrott closed 7 months ago

ryanshrott commented 10 months ago

I get this error on occasion
ryan@ryan-MacBookPro:~/Documents$ python3 photos.py Traceback (most recent call last): File "/home/ryan/Documents/photos.py", line 28, in ap = AmazonPhotos() File "/home/ryan/.local/lib/python3.10/site-packages/amazon_photos/api.py", line 70, in init self.root, self.owner_id = self._get_root() File "/home/ryan/.local/lib/python3.10/site-packages/amazon_photos/api.py", line 466, in _get_root data = r.json() AttributeError: 'NoneType' object has no attribute 'json'

The-Judge commented 9 months ago

Exactly the same here:

  1. Extracted cookies from Chrome
  2. Set the EnvVars using:
    os.environ['SESSION_ID'] = "258..."
    os.environ['UBID_ACDCA'] = "261..."
    os.environ['AT_ACBCA'] = "Atza|I..."
  3. When executing ap = AmazonPhotos(), it takes quite some time (est. 1 Minute) before it throws exactly the same error:
    Traceback (most recent call last):
      File "/Users/marichter/Desktop/amazon_photos/01/main.py", line 10, in <module>
        ap = AmazonPhotos()
             ^^^^^^^^^^^^^^
      File "/Users/marichter/.local/share/virtualenvs/01-k_hNu90A/lib/python3.11/site-packages/amazon_photos/api.py", line 70, in __init__
        self.root, self.owner_id = self._get_root()
                               ^^^^^^^^^^^^^^^^
       File "/Users/marichter/.local/share/virtualenvs/01-k_hNu90A/lib/python3.11/site-packages/amazon_photos/api.py", line 466, in _get_root
        data = r.json()
               ^^^^^^
    AttributeError: 'NoneType' object has no attribute 'json'

My main.py:

import os
from amazon_photos import AmazonPhotos

os.environ['SESSION_ID'] = "258..."
os.environ['UBID_ACDCA'] = "261..."
os.environ['AT_ACBCA'] = "Atza|Iw..."

ap = AmazonPhotos()
The-Judge commented 9 months ago

I guess this is related to #4 :

It seems that AP works in a way, depending on which country TLD you use to browse AP (https://www.amazon.de/photos, https://www.amazon.ch/photos, ...) the names of these variables also get a country shortcode suffix (AT_ACBCA -> CA -> Canada, AT_ACBIT -> IT -> Italy, AT_ACBDE -> DE -> Germany, ...).

This also makes the hardcoded amazon.ca in api.py questionable and eventually the drive API URL is also wrong if from Europe, for example: https://cdws.eu-west-1.amazonaws.com/drive/v2/memories/v1/collections/this_day_filtered. Seems that Europe has it's own Base URL at https://cdws.eu-west-1.amazonaws.com.

trevorhobenshield commented 7 months ago

Thanks, nice catch. Just made the modifications.