![](/img/trans.png)
[英]Crontab to launch python script on raspberry pi causes import error
[英]Raspberry Pi Crontab script error
我在Raspberry Pi上具有以下腳本來發送SMS。 如果我輸入以下命令,它將運行:python tides_sms.py
問題是,我無法通過Crontab(* * * * * / usr / bin / python /home/pi/python_files/tides_sms.py)運行它。 該文件設置為:rwxr-xr-x
當我添加代碼以寫入文件時,該文件是通過Crontab創建的,但不會發送SMS。
任何幫助表示贊賞。
#!/usr/bin/python
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "**********************************"
auth_token = "********************************"
with open("tide_data.txt", "r") as file:
tides_array = file.read().splitlines()
tides_array.reverse()
elements = tides_array[0].split(' | ')
string=''
for element in elements:
string = '\n'.join([string, element])
client = TwilioRestClient(account_sid, auth_token)
message = client.sms.messages.create(body="Text from PI:\nTIDES" + string,
to="+44??????????",
from_="+44??????????")
通過cron運行腳本時,工作目錄為/
-文件系統根目錄。 在腳本中使用絕對路徑:
with open("/path/to/tide_data.txt", "r") as file:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.