Skip to main content
 首页 » 编程设计

php之python-gammu 不能与 sudo 一起工作

2025年02月15日32jillzhang

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

发送短信.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"Error opening device, it doesn't exist.", 'Code': 4, 'Where': 'Init'}

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

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

  2. 如果没有 sudo,我无法通过 php 运行它

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

设备-Raspberry pi 3

操作系统-Raspbian

请您参考如下方法:

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

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