从python调用Twilio时引发了Httplib2异常

时间:2016-11-17 13:17:20

标签: python python-2.7 ubuntu docker twilio

我正在尝试通过Twilio从Docker容器中运行的某些Python代码发送SMS消息。该容器是使用Python 2.7和最新的twilio-python辅助库从Ubuntu映像构建的。当调用TwilioRestClient messages.create()函数时,我得到下面的回溯。另外,我已经通过卷曲确认我可以到达网址“api.twilio.com”,如此容器的回溯中所示。有任何想法吗?

正在使用的代码......

import argparse
import requests
import time
import smtplib
from datetime import datetime
from twilio.rest import TwilioRestClient

def sendText( ToNumber, smsMsg):

# put your own credentials here

ACCOUNT_SID = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

AUTH_TOKEN = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

FromNumber = '+nnnnnnnnnnn'

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

client.messages.create(to = ToNumber,from_ = FromNumber,body = smsMsg,)

return True

...回溯

File "./siteminder3.py", line 15, in sendText
  message = client.messages.create(to=ToNumber,from_=FromNumber,body=smsMsg)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/messages.py", line 122, in create
  return self.create_instance(kwargs)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 365, in create_instance
  data=transform_params(body))
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 200, in request
  resp = make_twilio_request(method, uri, auth=self.auth, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 152, in make_twilio_request
  resp = make_request(method, uri, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/twilio/rest/resources/base.py", line 117, in make_request
  resp, content = http.request(url, method, headers=headers, body=data)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1609, in request
  (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1351, in _request
  (response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py", line 1278, in _conn_request
  raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at api.twilio.com

0 个答案:

没有答案