mcrute / pydora

Pandora API Client and Command Line Player written in Python
MIT License
62 stars 19 forks source link

Unable to login #66

Closed damnkrat closed 3 years ago

damnkrat commented 3 years ago

What happened: TypeError: Cannot mix str and non-str arguments

What you expected to happen: Normal login

How to reproduce it (as minimally and precisely as possible): I thing use this code:

from pandora.clientbuilder import SettingsDictBuilder

def play_music(url):
    # You'll need to implement this to do something like call VLC with the track to play it
    pass

# You will need to read the README, it has a link to a page that contains the values
# required for the below dictionary. You can copy/paste them to replace see_link_above
client = SettingsDictBuilder({
    "DECRYPTION_KEY": "[REDACTED]", "ENCRYPTION_KEY": "[REDACTED]",
    "PARTNER_USER": "[REDACTED]", "PARTNER_PASSWORD": "[REDACTED]",
    "DEVICE": "[REDACTED]",
    "PROXY": {'http': "http://89.187.177.96:80", 'https': "https://51.81.82.175:80"},
    "AUDIO_QUALITY": "highQuality"}).build()

client.login("My login", "my pass")

stations = client.get_station_list()

# A playlist has a fixed number of songs (3 IIRC) so you have to call get_playlist over and
# over to keep playing songs. Be careful here though, the Pandora server expects you to
# actually listen to the songs you get from it, if you call this API too often then Pandora will
# start to rate-limit you and fail your requests. The best idea is to call this no more than every
# (play_list_item_count * 3 minutes) minutes to avoid being rate limited.
first_station_playlist = stations[0].get_playlist()

first_track = first_station_playlist[0]

print(f"Now playing {first_track.song_name} by {first_track.artist_name} on album {first_track.album_name}\n"
      f"{len(first_station_playlist)=}")

play_music(first_track.audio_url)

You wil get this error:

TypeError: Cannot mix str and non-str arguments
Traceback (most recent call last):
  File "/run/media/dannkunt/01D67E9E24F55A00/Programing/Python/bef_music_bot/pandora_mus.py", line 17, in 
    client.login("my account", "strong pass")
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/pandora/client.py", line 64, in login
    return self._authenticate()
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/pandora/client.py", line 67, in _authenticate
    self._partner_login()
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/pandora/client.py", line 49, in _partner_login
    partner = self.transport(
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/pandora/transport.py", line 51, in function
    return func(*args, **kwargs)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/pandora/transport.py", line 241, in __call__
    result = self._make_http_request(url, data, params)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/pandora/transport.py", line 192, in _make_http_request
    result = self._http.post(url, data=data, params=params)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/requests/sessions.py", line 590, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/requests/adapters.py", line 412, in send
    conn = self.get_connection(request.url, proxies)
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/requests/adapters.py", line 304, in get_connection
    proxy = prepend_scheme_if_needed(proxy, 'http')
  File "/home/dannkunt/.venvs/bef_music_bot39_venv/lib/python3.9/site-packages/requests/utils.py", line 910, in prepend_scheme_if_needed
    scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)
  File "/usr/lib/python3.9/urllib/parse.py", line 389, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "/usr/lib/python3.9/urllib/parse.py", line 122, in _coerce_args
    raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

Anything else we need to know?:

Environment:

mcrute commented 3 years ago

This error isn't caused by pydora, instead it's the PROXY argument. That argument should just be the URL of your proxy as a string, not a dictionary.

Also I need to amend my code sample. This line won't work:

first_track = first_station_playlist[0]

It should instead be:

first_track = next(first_station_playlist)

Because the playlist is returned as an iterator not a list. Similarly, you can not len() an iterator.

In my testing when I used "http://89.187.177.96:80 as a proxy the error you mentioned no longer appears.