您首先需要安裝PIP,在此之後安裝python-監務,如果你使用的是Linux是遠遠超過這個使用其他操作系統更好。
這個庫很簡單。
#!/usr/bin/env python
# Sample script to show how to send SMS
import gammu
import sys
# Create object for talking with phone
sm = gammu.StateMachine()
# Optionally load config file as defined by first parameter
if len(sys.argv) >= 2:
# Read the configuration from given file
sm.ReadConfig(Filename = sys.argv[1])
# Remove file name from args list
del sys.argv[1]
else:
# Read the configuration (~/.gammurc)
sm.ReadConfig()
# Check parameters
if len(sys.argv) != 2:
print 'Usage: sendsms.py [configfile] RECIPIENT_NUMBER'
sys.exit(1)
# Connect to the phone
sm.Init()
# Prepare message data
# We tell that we want to use first SMSC number stored in phone
message = {
'Text': 'python-gammu testing message',
'SMSC': {'Location': 1},
'Number': sys.argv[1],
}
# Actually send the message
sm.SendSMS(message)
這裏是一個鏈接的更多信息。 http://wammu.eu/docs/manual/python/examples.html
記住,你可以使用控制檯完全沒有問題,這樣做......你必須記住的僅僅是因爲監務安裝在系統上的非根發送消息之前,應用sudo命令。
你是如何運行它?你需要在命令行執行'python setup.py install'。 – rlms
感謝您的迅速回復。我嘗試了你的方法,結果相同。我需要安裝pkg-config嗎?我不知道那是如何工作的。 –
問題的一部分似乎是因爲我在Windows上運行的事實。 「命令」中的** getstatusoutput **函數看起來不是對Windows友好的。參考:http://stackoverflow.com/a/1198935/2259400 我使用鏈接新的getstatusoutput()實現。 現在我得到另一個錯誤: 說「無法找到vcvarsall.bat」 –