# Play streamsong using python and raspberry pi

**URL:** <https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616>\
**Category:** Pi MusicBox (archive)\
**Created:** [March 12, 2015, 11:36pm UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616 "2015-03-12T23:36:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaime\_Andres\_Rincon\_](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jaime\_Andres\_Rincon\_](https://discourse.mopidy.com/u/Jaime_Andres_Rincon_)\
**Post date:** [March 12, 2015, 11:36pm UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616/1 "2015-03-12T23:36:47Z")

</div>

Hi my name is jaime ans now I am designing a application that can playing stream music using mopidy and spotify. This application must be executed in my Raspberry pi. My idea is to create a script that can get acces (login and pasword) and playing song.

My Question is how can I do this with python?. I compiled this code:

```
import spotify

username = ' *******'
password = ' *******'

print spotify. __version__ # is 1.11

def logged_in(session, error_type):
    if error_type is spotify.ErrorType.OK:
        print('Logged in as %s' % session.user)
    else:
        print('Login failed: %s' % error_type)

session = spotify.Session()
session.on(spotify.SessionEvent.LOGGED_IN, logged_in)
session.login(username, password)

```

and this is the error:

> Traceback (most recent call last):  
> File “/home/jarain78/Dropbox/PythonWorkSpace/MopidyExample/ **init**.py”, line 19, in   
> session.on(spotify.SessionEvent.LOGGED\_IN, logged\_in)  
> AttributeError: ‘spotify.Session’ object has no attribute ‘on’

Thanks for the help

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [March 13, 2015, 12:23am UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616/3 "2015-03-13T00:23:49Z")

</div>

What you have written there looks like pyspotify v2.x code but your version  
of pyspotify is v1.x.

Mopidy itself is a music server and already provides a way to stream music  
from Spotify through the Mopidy-Spotify extension. Are you sure you can’t  
just use this rather than write your own code? I’m not trying to put you  
off if you want to do so, just save you some time.

---

<div class="post-metadata">

**Author:** ![Jaime\_Andres\_Rincon\_](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jaime\_Andres\_Rincon\_](https://discourse.mopidy.com/u/Jaime_Andres_Rincon_)\
**Post date:** [March 17, 2015, 12:08am UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616/5 "2015-03-17T00:08:00Z")

</div>

Hi thanks for your answer, you told me that when I have a connection between mopidy and spotify is posible get access to search any song or get acces to my playlist. I need this, but using python script, now my mopidy and my spotify is connect, but only can play music using web server and I don’t want it. I need that when my mopidy and my spotify are connected execute my script in python and search e.g Metallica and play Fuel.

Thanks

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [March 17, 2015, 3:21pm UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616/6 "2015-03-17T15:21:42Z")

</div>

You can also control Mopidy through the MPD protocol. You could use python-mpd or python-mpd2. [http://pythonhosted.org/python-mpd2/topics/getting-started.html](http://pythonhosted.org/python-mpd2/topics/getting-started.html)

---

<div class="post-metadata">

**Author:** ![Jaime\_Andres\_Rincon\_](https://avatars.discourse-cdn.com/v4/letter/j/258eb7/32.png) [@Jaime\_Andres\_Rincon\_](https://discourse.mopidy.com/u/Jaime_Andres_Rincon_)\
**Post date:** [March 18, 2015, 6:02pm UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616/8 "2015-03-18T18:02:39Z")

</div>

Hi kingosticks thanks for your answer, this is what I was looking for 😄 .

Thanks

Jarain78

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [February 19, 2026, 11:47am UTC](https://discourse.mopidy.com/t/play-streamsong-using-python-and-raspberry-pi/616/9 "2026-02-19T11:47:46Z")

</div>


