[GH-ISSUE #63] encode error #32

Closed
opened 2026-02-27 23:20:29 +03:00 by kerem · 6 comments
Owner

Originally created by @blackjack4494 on GitHub (Aug 20, 2015).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/63

Traceback (most recent call last):
File "playlist.py", line 30, in
print playlist['name']
File "C:\Python27\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2013' in position
11: character maps to

so u'\u2013' is a dash "-"

Originally created by @blackjack4494 on GitHub (Aug 20, 2015). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/63 Traceback (most recent call last): File "playlist.py", line 30, in <module> print playlist['name'] File "C:\Python27\lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode character u'\u2013' in position 11: character maps to <undefined> so u'\u2013' is a dash "-"
kerem 2026-02-27 23:20:29 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@CDeLeon94 commented on GitHub (Mar 28, 2019):

Same issue:
UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 2: character maps to <undefined>

Particularly in my case when I try printing out a json response that contains this artist:

spotify:artist:1tcqeQAROtzEdmsNer8YXM

The i I believe is the odd one, from looking up \u0131. A brief search yields a suggestion to check for the response's Unicode format and use the same thing when printing to stdout.

<!-- gh-comment-id:477425195 --> @CDeLeon94 commented on GitHub (Mar 28, 2019): Same issue: `UnicodeEncodeError: 'charmap' codec can't encode character '\u0131' in position 2: character maps to <undefined>` Particularly in my case when I try printing out a json response that contains this artist: `spotify:artist:1tcqeQAROtzEdmsNer8YXM` The `i` I believe is the odd one, from looking up `\u0131`. A brief search yields a suggestion to check for the response's Unicode format and use the same thing when printing to stdout.
Author
Owner

@stephanebruckert commented on GitHub (Jan 17, 2020):

I couldn't reproduce it with the given artist. Please let me know if it happens again and share your code, not just the error. Also make sure you upgrade:

pip install spotipy --upgrade
<!-- gh-comment-id:575759583 --> @stephanebruckert commented on GitHub (Jan 17, 2020): I couldn't reproduce it with the given artist. Please let me know if it happens again and share your code, not just the error. Also make sure you upgrade: pip install spotipy --upgrade
Author
Owner

@bjobo commented on GitHub (Feb 9, 2020):

I get the same error, when I tried to fetch songs with a German 'Umlaut' (äöü). I'm using Python 3.4.2 (can't upgrade because it's bundeld with volumio).

Traceback (most recent call last): File "spotify_helper3.py", line 23, in <module> print(playlist['name']) UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 2: ordinal not in range(128)

I used a code example from the documentation

`
import sys
import spotipy
import spotipy.util as util

if len(sys.argv) > 1:
username = sys.argv[1]
else:
print("Whoops, need your username!")
print("usage: python user_playlists.py [username]")
sys.exit()

token = util.prompt_for_user_token(username)

if token:
sp = spotipy.Spotify(auth=token)
playlists = sp.user_playlists(username)
for playlist in playlists['items']:
print(playlist['name'])
else:
print("Can't get token for", username)
`

<!-- gh-comment-id:583895293 --> @bjobo commented on GitHub (Feb 9, 2020): I get the same error, when I tried to fetch songs with a German 'Umlaut' (äöü). I'm using Python 3.4.2 (can't upgrade because it's bundeld with volumio). ` Traceback (most recent call last): File "spotify_helper3.py", line 23, in <module> print(playlist['name']) UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 2: ordinal not in range(128) ` I used a code example from the documentation ` import sys import spotipy import spotipy.util as util if len(sys.argv) > 1: username = sys.argv[1] else: print("Whoops, need your username!") print("usage: python user_playlists.py [username]") sys.exit() token = util.prompt_for_user_token(username) if token: sp = spotipy.Spotify(auth=token) playlists = sp.user_playlists(username) for playlist in playlists['items']: print(playlist['name']) else: print("Can't get token for", username) `
Author
Owner

@stephanebruckert commented on GitHub (Feb 9, 2020):

Hey @bjobo can you please provide an artist ID or public playlist ID? thx

<!-- gh-comment-id:583895514 --> @stephanebruckert commented on GitHub (Feb 9, 2020): Hey @bjobo can you please provide an artist ID or public playlist ID? thx
Author
Owner

@bjobo commented on GitHub (Feb 10, 2020):

Example Track-ID: spotify:track:1dbd8HmdfD4BSIkIMoom3l

I tried it successfully on a different Raspberry Pi with Python 3.7.3 (default, Dec 20 2019, 18:57:59).
I don't know if the error results from using Python 3.4.2 (can't upgrade) or a wrong encoding. Any ideas?

<!-- gh-comment-id:584064433 --> @bjobo commented on GitHub (Feb 10, 2020): Example Track-ID: spotify:track:1dbd8HmdfD4BSIkIMoom3l I tried it successfully on a different Raspberry Pi with Python 3.7.3 (default, Dec 20 2019, 18:57:59). I don't know if the error results from using Python 3.4.2 (can't upgrade) or a wrong encoding. Any ideas?
Author
Owner

@bjobo commented on GitHub (Feb 10, 2020):

After some testing I found out the problem is caused by the file system encoding:

Python 3.4.2 (default, Sep 26 2018, 07:16:01)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'utf-8'
>>> sys.getfilesystemencoding()
'ascii'

If I set the env export PYTHONIOENCODING=utf-8 everything works fine. (However I don't know which other consequences it does have).

Long story short: Ticket can be closed. It's not caused by Spotipy.

<!-- gh-comment-id:584226129 --> @bjobo commented on GitHub (Feb 10, 2020): After some testing I found out the problem is caused by the file system encoding: ``` Python 3.4.2 (default, Sep 26 2018, 07:16:01) [GCC 4.9.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.getdefaultencoding() 'utf-8' >>> sys.getfilesystemencoding() 'ascii' ``` If I set the env `export PYTHONIOENCODING=utf-8` everything works fine. (However I don't know which other consequences it does have). Long story short: Ticket can be closed. It's not caused by Spotipy.
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#32
No description provided.