我使用PythonAnywhere运行一个简单的脚本。这是一个试验,我写了一个脚本,每小时给我发一条短信。但每次我运行我的脚本时都会显示错误。
我的剧本是:
from twilio.rest import TwilioRestClient
from time import sleep
client = TwilioRestClient('AC******************', '**********************')
while True:
client.messages.create(
to="+1123456789",
from_="+1987654321",
body="Trial.",
)
print('Message Sent!')
sleep(3600)
错误是:
Traceback (most recent call last):
File "/home/dhruvsomani/sms.py", line 12, in <module>
body="Trial.",
File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/messages.py", line 122, in create
return self.create_instance(kwargs)
File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/base.py", line 341, in create_instance
data=transform_params(body))
File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/base.py", line 193, in request
resp = make_twilio_request(method, uri, auth=self.auth, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/base.py", line 148, in make_twilio_request
resp = make_request(method, uri, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/twilio/rest/resources/base.py", line 115, in make_request
resp, content = http.request(url, method, headers=headers, body=data)
File "/usr/local/lib/python3.4/dist-packages/httplib2/__init__.py", line 1292, in request
(response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/local/lib/python3.4/dist-packages/httplib2/__init__.py", line 1042, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/local/lib/python3.4/dist-packages/httplib2/__init__.py", line 966, in _conn_request
conn.connect()
File "/usr/lib/python3.4/http/client.py", line 1223, in connect
super().connect()
File "/usr/lib/python3.4/http/client.py", line 834, in connect
self.timeout, self.source_address)
File "/usr/lib/python3.4/socket.py", line 512, in create_connection
raise err
File "/usr/lib/python3.4/socket.py", line 503, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
我无法找到解决此问题的方法。我向你保证,与Twilio相关的细节是正确的。这是PythonAnywhere安全性错误。请告诉我如何克服这一点。
答案 0 :(得分:2)
PythonAnywhere dev在这里:我们最终在经常来回之后完成了这个工作 - 看来twilio客户端库依赖的httplib2库忽略了Python 3.x的代理设置。
解决方案是使用Python 2.7。