mpalazzolo / apple-music-python

A python wrapper for the Apple Music API
MIT License
94 stars 15 forks source link

AttributeError: 'HTTPError' object has no attribute 'headers' #3

Closed joaolsilva closed 5 years ago

joaolsilva commented 5 years ago

The retry code of client.py (line 115) tries to access e.headers that don't exist.

requests==2.22.0 apple-music-python==1.0.2

Traceback (most recent call last):
  File "/home/username/.virtualenvs/env/project/lib/python3.5/site-packages/applemusicpy/client.py", line 107, in _get
    return self._call('GET', url, kwargs)
  File "/home/username/.virtualenvs/env/project/lib/python3.5/site-packages/applemusicpy/client.py", line 92, in _call
    r.raise_for_status()  # Check for error
  File "/home/username/.virtualenvs/env/project/lib/python3.5/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 504 Server Error: Gateway Time-out for url: https://api.music.apple.com/v1/catalog/us/songs/962218666

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
[...]
  File "/home/username/.virtualenvs/env/project/lib/python3.5/site-packages/applemusicpy/client.py", line 362, in song
    return self._get_resource(song_id, 'songs', storefront=storefront, l=l, include=include)
  File "/home/username/.virtualenvs/env/project/lib/python3.5/site-packages/applemusicpy/client.py", line 151, in _get_resource
    return self._get(url, **kwargs)
  File "/home/username/.virtualenvs/env/project/lib/python3.5/site-packages/applemusicpy/client.py", line 115, in _get
    sleep_seconds = int(e.headers.get('Retry-After', delay))
AttributeError: 'HTTPError' object has no attribute 'headers'
mpalazzolo commented 5 years ago

I will fix this and update the code

mpalazzolo commented 5 years ago

I adjusted the HTTPError handler so you shouldn't get the AttributeError anymore. It will delay for some seconds and then retry the call until it hits the maximum retry limit.