EDIT 2: As #ximzend said, spotipy has moved to playlist_items instead of playlist_tracks
EDIT 1: In the process of moving to a curses interface, I changed the progress bar to a tqdm one (rather than rich), and that seemed to solve my problem. I did also upgrade spotipy (after it started working) but no change was needed in the API code ¯( ツ )/¯ so idk if rich was breaking the API req somehow or whatever
Thought I would put this here to help anyone in the future ツ
Spotipy throws this error when trying to retrieve data about tracks in a playlist
requests.exceptions.HTTPError: 404 Client Error: Not Found for url:
The error is thrown on the line below, specifically the self.sp.playlist_tracks(playlist_uri)['items'] part (The progress.track is a progress bar for the loop from rich)
for song in progress.track(self.sp.playlist_tracks(playlist_uri)['items'], description='Listing songs...'):
Full traceback is:
HTTP Error for GET to https://api.spotify.com/v1/playlists/4wi8hpuh4oyjtivbzk3k9n/tracks with Params: {'limit': 100, 'offset': 0, 'fields': None, 'market': None, 'additional_types': 'track'} returned 404 due to Not found.
Traceback (most recent call last):
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 245, in _internal_call
response.raise_for_status()
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\requests\models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.spotify.com/v1/playlists/4wi8hpuh4oyjtivbzk3k9n/tracks?limit=100&offset=0&additional_types=track
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "t:\projects\youtusic\main.py", line 132, in <module>
main()
File "t:\projects\youtusic\main.py", line 119, in main
track_list = obj.sp_get_tracks(playlist_uri)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "t:\projects\youtusic\youtusic.py", line 104, in sp_get_tracks
for song in progress.track(self.sp.playlist_tracks(playlist_uri)['items'], description='Listing songs...'):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 657, in playlist_tracks
return self.playlist_items(playlist_id, fields, limit, offset,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 681, in playlist_items
return self._get(
^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 297, in _get
return self._internal_call("GET", url, payload, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "T:\projects\youtusic\youtusic-env\Lib\site-packages\spotipy\client.py", line 267, in _internal_call
raise SpotifyException(
spotipy.exceptions.SpotifyException: http status: 404, code:-1 - https://api.spotify.com/v1/playlists/4wi8hpuh4oyjtivbzk3k9n/tracks?limit=100&offset=0&additional_types=track:
Not found., reason: None
The code I was using was as follows:
def sp_get_tracks(self, playlist_link: str) -> list:
'''
Uses [spotipy](https://pypi.org/project/spotipy/) to retrieve
a list of songs in the playlist provided. Returns a list to be
used with `grab_yt_links`
'''
playlist_uri = playlist_link.split('/')[-1].split('?')[0]
song_titles = []
for song in progress.track(self.sp.playlist_tracks(playlist_uri)['items'], description='Listing songs...'):
track_name: str = song['track']['name']
artist_name: str = song['track']['artists'][0]['name']
track_name = track_name.replace(' ', '+')
artist_name = artist_name.replace(' ', '+')
song_titles.append(f'{artist_name}+{track_name}')
return song_titles
It should returns a list of all the songs (and artists) in the playlist. (The progress.track is a progress bar for the loop from rich). The 404 confuses me because my network connection is fine and I am able to perform Google searches etc
Additionally, the playlist only has 19 songs in so should be resticted by the limits I have read elsewhere
You get this error, because Spotify made a code breaking change to its API.
SpotiPy has fixed this issue by releasing an upgrade.
To install this upgrade, open a command prompt and run pip install spotipy --upgrade.
After the upgrade, you need to use playlist_items(playlist_id, fields=None, limit=100, offset=0, market=None, additional_types=('track', 'episode')). playlist_tracks is deprecated.
Related
Im trying to launch an ml-engine jobs submit training using a cloud composer, i'm using this guide for instructions recommendation-system-tensorflow-deploy.
Im using a plugin which google created (see the implementation here)
Im trying to make it work on python version 3.5, this by changing line 206 from:
training_request = {
'jobId': job_id,
'trainingInput': {
'scaleTier': self._scale_tier,
'packageUris': self._package_uris,
'pythonModule': self._training_python_module,
'region': self._region,
'args': self._training_args,
'masterType': self._master_type
}
To:
training_request = {
'jobId': job_id,
'trainingInput': {
'scaleTier': self._scale_tier,
'packageUris': self._package_uris,
'pythonModule': self._training_python_module,
'region': self._region,
'args': self._training_args,
'masterType': self._master_type,
'python-version': '3.5' #self._python_version
}
I also tried to add to it the run time version (runtime-version='1.12') but i keep on getting the following error:
[2019-01-20 11:58:36,331] {models.py:1594} ERROR - <HttpError 400 when requesting https://ml.googleapis.com/v1/projects/hallowed-forge-577/jobs?alt=json returned "Invalid JSON payload received. Unknown name "python-version" at 'job.training_input': Cannot find field.">
Traceback (most recent call last)
File "/usr/local/lib/airflow/airflow/models.py", line 1492, in _run_raw_tas
result = task_copy.execute(context=context
File "/home/airflow/gcs/plugins/ml_engine_plugin.py", line 241, in execut
self._project_id, training_request, check_existing_job
File "/home/airflow/gcs/plugins/ml_engine_plugin.py", line 79, in create_jo
request.execute(
File "/usr/local/lib/python3.6/site-packages/oauth2client/util.py", line 135, in positional_wrappe
return wrapped(*args, **kwargs
File "/usr/local/lib/python3.6/site-packages/googleapiclient/http.py", line 838, in execut
raise HttpError(resp, content, uri=self.uri
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://ml.googleapis.com/v1/projects/hallowed-forge-577/jobs?alt=json returned "Invalid JSON payload received. Unknown name "python-version" at 'job.training_input': Cannot find field."
[2019-01-20 11:58:36,334] {models.py:1623} INFO - Marking task as FAILED.
[2019-01-20 11:58:36,513] {models.py:1627} ERROR - Failed to send email to: ['airflow#example.com']
[2019-01-20 11:58:36,516] {models.py:1628} ERROR - HTTP Error 401: Unauthorized
Traceback (most recent call last)
File "/usr/local/lib/airflow/airflow/models.py", line 1625, in handle_failur
self.email_alert(error, is_retry=False
File "/usr/local/lib/airflow/airflow/models.py", line 1778, in email_aler
send_email(task.email, title, body
File "/usr/local/lib/airflow/airflow/utils/email.py", line 44, in send_emai
return backend(to, subject, html_content, files=files, dryrun=dryrun, cc=cc, bcc=bcc, mime_subtype=mime_subtype
File "/usr/local/lib/airflow/airflow/contrib/utils/sendgrid.py", line 116, in send_emai
_post_sendgrid_mail(mail.get()
File "/usr/local/lib/airflow/airflow/contrib/utils/sendgrid.py", line 122, in _post_sendgrid_mai
response = sg.client.mail.send.post(request_body=mail_data
File "/usr/local/lib/python3.6/site-packages/python_http_client/client.py", line 252, in http_reques
return Response(self._make_request(opener, request, timeout=timeout)
File "/usr/local/lib/python3.6/site-packages/python_http_client/client.py", line 176, in _make_reques
raise ex
python_http_client.exceptions.UnauthorizedError: HTTP Error 401: Unauthorize
Notice that the python version actually changes (to 3.6 from the original 2.7) so changing the python version, does something, but then gets stuck
Any help on what i'm missing here will be awesome!
It seems like the example uses an old version of airflow MLEngineTrainingOperator.
The last version implements the runtime-version/python-version training params.
Use the current version:
mlengine_operator.py
I've seen a couple of questions that already asked this but there were no responses, so I'll give it a try. When I use the following code:
import praw, time
r = praw.Reddit(user_agent="Bot experiment by redacted")
r.login('redacted', 'redacted')
I get a connection error that has the following traceback:
Traceback (most recent call last):
File "redacted", line 5, in <module>
r.login('redacted', 'redacted')
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/praw/__init__.py", line 1263, in login
self.request_json(self.config['login'], data=data)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/praw/decorators.py", line 161, in wrapped
return_value = function(reddit_session, *args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/praw/__init__.py", line 519, in request_json
response = self._request(url, params, data)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/praw/__init__.py", line 383, in _request
_raise_response_exceptions(response)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/praw/internal.py", line 172, in _raise_response_exceptions
response.raise_for_status()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/requests/models.py", line 831, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 403 Client Error: Forbidden
I have tried this from python 3.4 and 2.7, I've tried running from IDLE and from the terminal. I've tried leaving my username and password out and logging in when prompted. I've tried from my Mac in my hotel room and a Windows machine from work and I get the same error everytime. I've tried from my bot account that I just made and my normal account. Does anyone have any ideas?
The issue was that I had the word 'bot' in my user_agent string. After it was removed, there were no problems.
I'm getting an error when trying to upload a custom module for a trigger app. I'm not sure what's going on; it looks like maybe a bad response a badly formatted json.
Error in remote call to api.post_files: Forge API call to module/admob/version went wrong: Expecting object: line 9 column 1 (char 174)
Traceback (most recent call last):
File "/Users/kevzettler/Library/Trigger Toolkit/build-tools/forge/async.py", line 106, in run
result = self._target(*self._args, **self._kwargs)
File "/Users/kevzettler/Library/Trigger Toolkit/trigger/api/api.py", line 20, in post_files
return forge_tool.singleton.remote._api_post(method, data=data, cookies=cookies, files=opened_files)
File "/Users/kevzettler/Library/Trigger Toolkit/build-tools/forge/remote.py", line 475, in _api_post
_check_api_response_for_error(url, 'POST', resp)
File "/Users/kevzettler/Library/Trigger Toolkit/build-tools/forge/remote.py", line 121, in _check_api_response_for_error
_raise_if_json_error(content_dict, error_template, resp, url)
File "/Users/kevzettler/Library/Trigger Toolkit/build-tools/forge/remote.py", line 81, in _raise_if_json_error
raise RequestError(resp, error_message, errors=errors)
RequestError: Forge API call to module/admob/version went wrong: Expecting object: line 9 column 1 (char 174)
It looks like the content of your config_schema.json file is invalid.
Unfortunately the error message you see isn't very useful. The good news is newer platform versions have better validation of local files before upload, so if you develop your module against a newer platform version errors like this should be listed in the Toolkit before upload.
I am trying to get a recent status of a twitter user. I type in the following:
>>> from twitter import *
>>> t = Twitter(auth=OAuth(...))
>>> t.statuses.friends_timeline(id="StephenAtHome")
I get the following error at the last line:
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
t.statuses.friends_timeline(id="StephenAtHome")
File "twitter\api.py", line 204, in __call__
return self._handle_response(req, uri, arg_data, _timeout)
File "twitter\api.py", line 235, in _handle_response
raise TwitterHTTPError(e, uri, self.format, arg_data)
TwitterHTTPError: Twitter sent status 404 for URL: 1.1/statuses/friends_timeline/StephenAtHome.json using parameters (oauth_consumer_key=i1xQ3YKmmUI9pKlYDmSPeA&oauth_nonce=12051576929978547960&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1371245218&oauth_token=1517563807-75iFGXWHxMvzzsqrIs5W4tCb4OwFG4eisnDYRst&oauth_version=1.0&oauth_signature=m0LDp%2FdkJLMr3sHPnFQkLKlDTrE%3D)
details: {"errors":[{"message":"Sorry, that page does not exist","code":34}]}
How do I fix this error. I know that the page exists
The problem is that twitter API was upgraded to 1.1 version and friends_timeline was deprecated (see docs). Use home_timeline instead (user_timeline should work but doesn't):
t.statuses.home_timeline(user_id="gvanrossum")
Hope that helps.
I'm using the prestashop API prestapyt
I add a category by hand in my site, but when I'm trying to edit via the API, it fails.
Even the most simple thing, does not work:
ps = PrestaShopWebServiceDict(config.DOMAIN, config.KEY)
xml = ps.get('categories', 35)
ps.edit('categories',35,xml)
The xml (type DICT) loads ok, but the .edit() fails.
Here is the response
Traceback (most recent call last):
File "C:\Users\noukeys\Documents\psapi\main.py", line 31, in <module>
ps.edit('categories',35,xml)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 333, in edit
return self.edit_with_url(full_url, content)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 452, in edit_with_url
return super(PrestaShopWebServiceDict, self).edit_with_url(url, xml_content)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 344, in edit_with_url
return self._parse(self._execute(url, 'PUT', body=unicode_encode.encode(content), add_headers=headers)[2])
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 171, in _execute
self._check_status_code(status_code)
File "C:\Python27\lib\site-packages\prestapyt\prestapyt.py", line 125, in _check_status_code
% (status_code, message_by_code[status_code]), status_code)
prestapyt.prestapyt.PrestaShopWebServiceError: 'This call to PrestaShop Web Services failed and returned an HTTP status of 400. That means: Bad Request.'
I'm having issues with edits also, but I am getting a 501 error. Turns out my host does not allow PUT requests.
You can turn on debugging in the api.
prestashop.debug = True
And then turn on display_errors in config.inc.php for your shop. This helped me debug why the request was bad. The error messages are pretty clear.