Twilio从python错误发送短信

时间:2017-07-04 19:25:01

标签: python sms twilio

我正在尝试按照Twilio中的教程从Python发送SMS消息。我已经按照他们的代码,但我收到了这个错误:

[root@helios03 ~]# python sms.py
Traceback (most recent call last):
  File "sms.py", line 10, in <module>
    message = client.api.account.messages.create(to="+12316851234",
  File "/usr/lib/python2.6/site-packages/twilio/rest/__init__.py", line 138, in api
    from twilio.rest.api import Api
  File "/usr/lib/python2.6/site-packages/twilio/rest/api/__init__.py", line 10, in <module>
    from twilio.rest.api.v2010 import V2010
  File "/usr/lib/python2.6/site-packages/twilio/rest/api/v2010/__init__.py", line 9, in <module>
    from twilio.base.version import Version
  File "/usr/lib/python2.6/site-packages/twilio/base/version.py", line 4, in <module>
    from twilio.base import values
  File "/usr/lib/python2.6/site-packages/twilio/base/values.py", line 12
    return {k: v for k, v in iteritems(d) if v != unset}
                   ^
SyntaxError: invalid syntax

思考?我做了一个“pip install twilio”来安装帮助器..

他们的示例代码是:

# /usr/bin/env python
# Download the twilio-python library from http://twilio.com/docs/libraries
from twilio.rest import Client

# Find these values at https://twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = Client(account_sid, auth_token)

message = client.api.account.messages.create(to="+12316851234",
                                             from_="+15555555555",
                                             body="Hello there!")

我已经替换了数字和帐户sid /令牌来匹配我的信息......

1 个答案:

答案 0 :(得分:0)

PEP 274 -- Dict Comprehensions州:All implementation details were resolved in the Python 2.7 and 3.0 time-frame.

您正在使用 python2.6