python-gammu不使用sudo

时间:2017-08-21 15:40:28

标签: php python raspberry-pi raspberry-pi3 gammu

我正在尝试从PHP运行SMS发送python脚本。

SendSMS.py:

#!/usr/bin/env python

import gammu

sm=gammu.StateMachine()
sm.ReadConfig()
sm.Init()

message={
        'SMSC':{'Location':1},
        'Text':'blah blah bllah',
        'Number':'xxxxxxxxx
}
sm.SendSMS(message)

当我使用“sudo”从终端运行它时它不起作用。但没有“sudo”正常工作

错误:

  

gammu.ERR_DEVICENOTEXIST:{'Text':u“打开设备时出错,它没有   存在。“,'代码':4,'哪里':'初始'}

我想使用shell_exec()从php脚本运行SMS脚本。问题是:

  1. 我无法使用sudo运行SMS脚本

  2. 我无法通过没有sudo的php运行它

  3. 请告诉我如何解决这个问题

    Device-Raspberry pi 3

    OS- Raspbian

1 个答案:

答案 0 :(得分:1)

很可能它找不到配置文件,默认情况下它是searched in user home directory,当通过sudo执行时它是不同的。

你可以specify path to configuration file on command line但最好不要以root身份执行gammu和configure the device to be accessible by user