SoCo with python 3.4.2

509 views
Skip to first unread message

Mark Blom

unread,
Oct 19, 2014, 4:16:08 PM10/19/14
to pytho...@googlegroups.com
Hi,

Disclaimer: I am new to python

I am trying to use the SoCo library to talk to my sonos system. First, I am trying to get this done on my windows 8 machine. When that is working, my goal is to run it on raspberry pi.

I have done a clean install of python 3.4.2 and dit pip install soco to install the soco package.

Now, when running the sonosshell.py script I found on GitHub, I am getting errors like:


C:\Temp>sonosshell.py 192.168.1.3
  File "C:\Temp\sonosshell.py", line 10
    print "Usage: sonoshell.py [speaker's IP|all] [cmd]"
                                                       ^
SyntaxError: Missing parentheses in call to 'print'

Googling for this error I found a person saying the this indicates that the python script was meant to run in python 2 instead of 3.

Is this correct? Does the SoCo module have to be run on python 2 or should it be possible to run it on 3 as well? And if so, what could cause the error I get?

Thanks!

Petter Aas

unread,
Oct 19, 2014, 6:13:42 PM10/19/14
to pytho...@googlegroups.com
It sounds like you have found a old version of what was later turned into https://github.com/SoCo/socos

When it comes to the actual error, the print statement in python2 has been changed to the print() function in python3.

If you want to read more about the print changes, check
http://legacy.python.org/dev/peps/pep-3105/

/Petter

Message has been deleted

Mark Blom

unread,
Oct 20, 2014, 2:43:30 AM10/20/14
to pytho...@googlegroups.com
Hi Peter,

Thanks for your reply!

I am bit confused now. The discover.py script with the legacy print statement that I was trying to run comes from:
https://github.com/SoCo/SoCo/tree/master/examples/commandline

To me, this seems to be the official and most current SoCo project?

In the project you mentioned: https://github.com/SoCo/socos I could not find an examples folder containing that discover.py script.

So, to be sure:
https://github.com/SoCo/SoCo is the project I should be looking at for python 3.x?

Grtz,

Mark


Kenneth Nielsen

unread,
Oct 20, 2014, 5:13:12 AM10/20/14
to pytho...@googlegroups.com
Hallo Mark

First of, yes, there is only one SoCo, at https://github.com/SoCo/SoCo and yes that is python 3 compatible.

With regards to the examples. As Petter mentioned, the first script you mentioned sonosshell.py, you must have found from somewhere else (an older version of SoCo). That was an examples of how to program a commandline shell for soco, so that you could type commands like "play" in a shell. That script ended up seeing so much interest that it was spun of into its own project.

With regards to discover.py, there you seem to have simply found a bug. When all the other python files was made python 3 compatible, this one seems to have been forgotten. You are welcome to open an issue for it at https://github.com/SoCo/SoCo/issues or if you do not wish to make a github account I can do it for you.

With regards to gettings started, there is a very minimal example in the tutorial in the documentation: http://soco.readthedocs.org/en/latest/index.html (which actually also seems to be slightly outdated but will work). The more correct way is, if you want to know which units you have:

Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import soco
>>> units = soco.discover()
>>> units
{SoCo("192.168.0.16"), SoCo("192.168.0.30"), SoCo("192.168.0.17")}

from here you can get to one of the units out by

>>> a_unit = units.pop()
>>> a_unit
SoCo("192.168.0.10")

If you already know the IP's of your units and don't expect them to change you can also skip this step and just instantiate the SoCo object with the IP-adress directly like so:
>>> import soco
>>> a_unit = soco.SoCo('192.168.0.10')
>>> a_unit
SoCo("192.168.0.10")


In both cases, this "a_unit" variable now contains an instance of the SoCo class, which is the main controller object for one of your Sonos speakers. On the object you can use all the commands listed and documented here: http://soco.readthedocs.org/en/latest/soco-mod.html#soco.SoCo

I hope this gets you going.

Regards Kenneth




--
You received this message because you are subscribed to the Google Groups "SoCo - Sonos Controller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-soco...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Blom

unread,
Oct 20, 2014, 2:52:01 PM10/20/14
to pytho...@googlegroups.com
Hi Kenneth,

Many thanks for your help! 

I have successfully run a python script on windows to play/stop my sonos. I will now try to get this to work on my raspberry pi :-)

For me, there is no need to modify the discover.py script but perhaps it will be helpful to other newbies like me :-)

Regards,

Mark

DPH

unread,
Oct 21, 2014, 3:01:24 AM10/21/14
to pytho...@googlegroups.com
Well done Mark.
I use Raspberry Pi with Sonos with no problem.
I have been using Python 2.7 as that was default with Raspberry Pi, but I understand they now have the option for 3 also.
Have fun,
Cheers David
Reply all
Reply to author
Forward
0 new messages