[GH-ISSUE #745] 'Response' object has no attribute 'txt' #452

Closed
opened 2026-02-27 23:22:42 +03:00 by kerem · 3 comments
Owner

Originally created by @ntorba on GitHub (Nov 16, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/745

Describe the bug
I'm running a query (that oddly enough, was working until this morning) and get an error from spotipy.

Your code

import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from dotenv import load_dotenv

load_dotenv()


def mac_miller_songs(n=5):
    mac_miller_uri = "spotify:artist:4LLpKhyESsyAXpc4laK94U"
    spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
    results = spotify.artist_top_tracks(mac_miller_uri)
    tracks = results["tracks"][:n]
    table_info = []
    for i_track in tracks:
        track_info = {}
        track_info["artist"] = i_track["artists"][0]["name"]
        track_info["name"] = i_track["name"]
        track_info["uri"] = i_track["uri"]
        track_info["img_sm"] = i_track["album"]["images"][-1]["url"]
        track_info["img_md"] = i_track["album"]["images"][1]["url"]
        track_info["img_lg"] = i_track["album"]["images"][0]["url"]
        table_info.append(track_info)
    return table_info
a = mac_miller_songs()

Expected behavior
Previously, this function successfully returned the song info.

Output

Traceback (most recent call last):
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 135, in _handle_oauth_error
    error_payload = response.json()
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/requests/models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/nicholastorba/Documents/GitHub/TurboQueue/query_spotify.py", line 33, in <module>
    a = mac_miller_songs()
  File "/Users/nicholastorba/Documents/GitHub/TurboQueue/query_spotify.py", line 10, in mac_miller_songs
    mac_miller_uri = "spotify:artist:4LLpKhyESsyAXpc4laK94U"
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 410, in artist_top_tracks
    return self._get("artists/" + trid + "/top-tracks", country=country)
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 297, in _get
    return self._internal_call("GET", url, payload, kwargs)
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 221, in _internal_call
    headers = self._auth_headers()
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 212, in _auth_headers
    token = self.auth_manager.get_access_token(as_dict=False)
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 238, in get_access_token
    token_info = self._request_access_token()
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 269, in _request_access_token
    self._handle_oauth_error(http_error)
  File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 143, in _handle_oauth_error
    error = response.txt or None
AttributeError: 'Response' object has no attribute 'txt'

Environment:

  • OS: [e.g. Windows, Mac]
  • Python version [e.g. 3.7.0]
  • spotipy version [e.g. 2.12.0]
  • your IDE (if using any) [e.g. PyCharm, Jupyter Notebook IDE, Google Colab]

Mac, python3.9

spotipy==2.19.0

Additional context
Add any other context about the problem here.

Originally created by @ntorba on GitHub (Nov 16, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/745 **Describe the bug** I'm running a query (that oddly enough, was working until this morning) and get an error from spotipy. **Your code** ``` import spotipy from spotipy.oauth2 import SpotifyClientCredentials from dotenv import load_dotenv load_dotenv() def mac_miller_songs(n=5): mac_miller_uri = "spotify:artist:4LLpKhyESsyAXpc4laK94U" spotify = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) results = spotify.artist_top_tracks(mac_miller_uri) tracks = results["tracks"][:n] table_info = [] for i_track in tracks: track_info = {} track_info["artist"] = i_track["artists"][0]["name"] track_info["name"] = i_track["name"] track_info["uri"] = i_track["uri"] track_info["img_sm"] = i_track["album"]["images"][-1]["url"] track_info["img_md"] = i_track["album"]["images"][1]["url"] track_info["img_lg"] = i_track["album"]["images"][0]["url"] table_info.append(track_info) return table_info a = mac_miller_songs() ``` **Expected behavior** Previously, this function successfully returned the song info. **Output** ```bash Traceback (most recent call last): File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 135, in _handle_oauth_error error_payload = response.json() File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/requests/models.py", line 910, in json return complexjson.loads(self.text, **kwargs) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/json/__init__.py", line 346, in loads return _default_decoder.decode(s) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/nicholastorba/Documents/GitHub/TurboQueue/query_spotify.py", line 33, in <module> a = mac_miller_songs() File "/Users/nicholastorba/Documents/GitHub/TurboQueue/query_spotify.py", line 10, in mac_miller_songs mac_miller_uri = "spotify:artist:4LLpKhyESsyAXpc4laK94U" File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 410, in artist_top_tracks return self._get("artists/" + trid + "/top-tracks", country=country) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 297, in _get return self._internal_call("GET", url, payload, kwargs) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 221, in _internal_call headers = self._auth_headers() File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/client.py", line 212, in _auth_headers token = self.auth_manager.get_access_token(as_dict=False) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 238, in get_access_token token_info = self._request_access_token() File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 269, in _request_access_token self._handle_oauth_error(http_error) File "/Users/nicholastorba/miniconda3/envs/turboqueue/lib/python3.9/site-packages/spotipy/oauth2.py", line 143, in _handle_oauth_error error = response.txt or None AttributeError: 'Response' object has no attribute 'txt' ``` **Environment:** - OS: [e.g. Windows, Mac] - Python version [e.g. 3.7.0] - spotipy version [e.g. 2.12.0] - your IDE (if using any) [e.g. PyCharm, Jupyter Notebook IDE, Google Colab] Mac, python3.9 spotipy==2.19.0 **Additional context** Add any other context about the problem here.
kerem 2026-02-27 23:22:42 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@browniebroke commented on GitHub (Oct 7, 2022):

Was fixed in #811, however the fix isn't released yet.

<!-- gh-comment-id:1271254564 --> @browniebroke commented on GitHub (Oct 7, 2022): Was fixed in #811, however the fix isn't released yet.
Author
Owner

@moehmeni commented on GitHub (Jan 28, 2023):

I think this should be closed since v2.21.0

<!-- gh-comment-id:1407372730 --> @moehmeni commented on GitHub (Jan 28, 2023): I think this should be closed since [v2.21.0](https://github.com/spotipy-dev/spotipy/releases/tag/2.21.0)
Author
Owner

@stephanebruckert commented on GitHub (Jan 28, 2023):

Thanks @rtcq, @browniebroke, closing!

<!-- gh-comment-id:1407372924 --> @stephanebruckert commented on GitHub (Jan 28, 2023): Thanks @rtcq, @browniebroke, closing!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#452
No description provided.