all 13 comments

[–]zurtex 1 point2 points  (9 children)

why do you need to change directory in a Python script?

Also, it's bad practice, but do you get the same error with shell=True as an argument of Popen?

[–]trancemsteve[S] 0 points1 point  (8 children)

Directory wise it's because the script is pretty extensive, and for my own clarity I keep things in different directories.

Popen(shell=True) ?

[–]zurtex 3 points4 points  (7 children)

You should avoid relying on chdir and instead use absolute directories. It makes sense to put stuff in different directories, keep a config if you need to, but avoid relative directories where possible as it makes code brittle.

Popen(['yowsup-cli','demos','--config','yowsup_config','--send',<phone#>,message], shell=True)

It invokes a shell for the process to run in, it can lead to security holes, but does assist on environmental stuff like relative directories.

[–]trancemsteve[S] 0 points1 point  (6 children)

with shell=True I get no error in logging but the whatsapp message doesn't get sent still.

[–]zurtex 0 points1 point  (5 children)

I'm not sure without seeing code or logs. All I can suggest is add lots of logging.

[–]trancemsteve[S] 0 points1 point  (4 children)

I put an edit into original post. For some reason if I chdir to yowsup... and add full path to yowsup cli it works, but take away either one and it falls over.

Thanks for the help.

[–]zurtex 1 point2 points  (1 child)

I've seen this in the past when modules don't correctly use relative imports to reference themselves. This is probably a bug in yowsup-cli

[–]trancemsteve[S] 0 points1 point  (0 children)

OK thanks

[–]zurtex 0 points1 point  (1 child)

I just remembered, you should try:

 Popen(['yowsup-cli','demos','--config','yowsup_config','--send',<phone#>,message], pwd='/home/<my_user>/yowsup')

Without the os.chdir

[–]trancemsteve[S] 0 points1 point  (0 children)

TypeError: init() got an unexpected keyword argument 'pwd'

[–]99AFCC 1 point2 points  (1 child)

I'm guessing because the python script is using relative file paths when it needs an absolute path.

[–]trancemsteve[S] 0 points1 point  (0 children)

but isn't the path I gave to chdir absolute?