#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    5
    Rep Power
    0

    Pexpect not reading config file


    I'm trying to use pexpect to open pianobar (a client for Pandora online radio).

    If I just start pianobar from the command line (not from my Python program), it logs in to Pandora automatically using info from the config file (Email, Password, TLS_fingerprint).

    If I run my script in IDLE, it also works. But if I run it from the command prompt, it acts like it doesn't see the config file, and asks me for my Email and Password.

    I can feed it my Email and Password, but I have no idea what to do with the TLS_fingerprint, and end up with 'TLS handshake failed'

    I am a total Newb, in over my head, but if I can get this to work it would be great. I am doing this on a Raspberry Pi, using the Raspian Wheezy Linux distro.

    Thanks, Zygo
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    "If I just start pianobar from the command line..."
    This means you issue the command pianobar at the bash prompt?
    $ pianobar


    "If I run my script in IDLE, it also works."
    Which script? Do you mean that you click the "run" button in an editing window?

    "But if I run it [your script?] from the command prompt [the idle prompt or the bash prompt?],"
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    5
    Rep Power
    0
    Originally Posted by b49P23TIvg
    "If I just start pianobar from the command line..."
    This means you issue the command pianobar at the bash prompt?
    $ pianobar
    Yes, exactly. Then pianobar works fine and loads my login info from the config file, completes the TLS handshake, and starts running.

    Originally Posted by b49P23TIvg
    "If I run my script in IDLE, it also works."
    Which script? Do you mean that you click the "run" button in an editing window?
    Yes

    Originally Posted by b49P23TIvg
    "But if I run it [your script?] from the command prompt [the idle prompt or the bash prompt?],"
    If I run my script from the bash prompt (either in a terminal emulator or after exiting the desktop) by typing "sudo python <Filename>" it starts up, but then asks for my Email (I can see this by looking at the buffer returned when the script times out).
    I was able to feed it my Email and Login by using "child.expect" and "child.send" to wait for and respond to the prompts, but now am stuck at TLS handshake failed.

    It's acting as if it can't see the info in the config file, I guess.

    Thanks for taking the time to look at this. I am trying to build an internet radio to give my wife for our anniversary. If I can crack this, I think I can do the rest, but I'm pretty stumped.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    I think, therefor, we need to see your script.

    When you run idle you might get a different version of python than with python.

    $ idle # uses python version 2.7
    $ python # python3
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    5
    Rep Power
    0
    Here is the relevant code:

    from pexpect import spawn

    child = spawn('/usr/bin/pianobar')
    #starts pianobar which then should log me on automatically with info from its config file

    print channel
    child.expect('station:') #looks for prompt from pianobar for ‘station:'
    print child.before
    child.sendline('35') #tells pianobar I’d like it to play station 35


    Thanks for the idea that it might be a version problem. I don't think it is, though, because the program runs fine otherwise, including several "print" statements elsewhere. My script is written in 2.7.3. Just to check, I tried running it in Python 3, and it wouldn't run at all because of the write statements.

    I figured out from the error message that it doesn't auto login when run from the bash prompt (it does this fine from idle).
    It is stopping and asking "Email:?", and so it never gets to "station:"

    I was able to get past this by adding 'child.expect' and 'child.sendline' statements to my script to enter the Email and Password, but then it stops because "TLS handshake failed"

    Since the Email, Password, and TLS info are all the config file, I figure it isn't accessing the config file for some reason.

    Thanks, Zygo
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    how about change your ~/.config/pianobar/config
    file?
    Code:
    tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0
    I installed pianobar,
    registered with pandora,
    got the TLS handshake problem,
    installed a config file with this fingerprint,
    and moved on to the next error:

    $ pianobar
    Welcome to pianobar (2012.05.06)! Press ? for a list of commands.
    (i) Login... Error: No error message available.
    /!\ Cannot start eventcmd. (No such file or directory)

    I hope this fixes your difficulty.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    5
    Rep Power
    0
    Thanks, but that's not it. Pianobar runs fine on its own, and I've got the right tls fingerprint. It just doesn't seem to be pulling it (or the Email or Password) from the config file when run as a child process with pexcept. I had that problem at first, too, but was able to jump that hurdle with the help of google. This one is proving more difficult.

    Originally Posted by b49P23TIvg
    how about change your ~/.config/pianobar/config
    file?
    Code:
    tls_fingerprint = 2D0AFDAFA16F4B5C0A43F3CB1D4752F9535507C0
    I installed pianobar,
    registered with pandora,
    got the TLS handshake problem,
    installed a config file with this fingerprint,
    and moved on to the next error:

    $ pianobar
    Welcome to pianobar (2012.05.06)! Press ? for a list of commands.
    (i) Login... Error: No error message available.
    /!\ Cannot start eventcmd. (No such file or directory)
    r
    I hope this fixes your difficulty.
  14. #8
  15. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    I feel like I'm chasing your tail. (Because I am.) I'm now up to

    (i) Login... Error: No error message available.


    Have you tried running it in the tilda terminal emulator?

    Maybe the code knows if it's connected to a terminal.
    [code]Code tags[/code] are essential for python code and Makefiles!
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    5
    Rep Power
    0
    Solved it with the help of someone over at stackoverflow. When running the script from the bash prompt, it was looking for the config in root. I'm not sure I understand why, but that's what it was doing. Putting a copy of the config file in /root/.config/pianobar/ solved the problem. Thanks!


    Originally Posted by b49P23TIvg
    I feel like I'm chasing your tail. (Because I am.) I'm now up to

    (i) Login... Error: No error message available.


    Have you tried running it in the tilda terminal emulator?

    Maybe the code knows if it's connected to a terminal.

IMN logo majestic logo threadwatch logo seochat tools logo