gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 05:00:48 26 4
gpt4 key购买 nike

我正在尝试从 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 .

关于php - python-gammu 不能与 sudo 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45801041/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com