【问题标题】:python twilio HTTPSConnectionPool(host='api.twilio.com', port=443) Max retries exceeded with urlpython twilio HTTPSConnectionPool(host='api.twilio.com', port=443) url 超出最大重试次数
【发布时间】:2017-08-17 09:25:52
【问题描述】:
sid = "*****************************"
token = "*****************************"
client = Client(sid, token)
message = client.messages.create(to="+91**********", from_="+12********", body="Hello from twilio")

在 sn-p 上运行时出现错误:

ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] 未知协议

我使用python3.4的虚拟环境运行它。 我不确定这里出了什么问题。

【问题讨论】:

  • 代码还有吗?您是否支持代理?
  • 不。我正在从托管 ubuntu 的 virtulbox 运行代码。
  • VirtualBox 是什么版本的?
  • 这是托管 ubuntu 14.04.5 的 Oracle Virtualbox 5.1.16

标签: python python-3.x ssl python-requests twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

我在这里并不完全确定,但我认为您的 TLS 支持可能已经过时了。我使用的是答案而不是评论,因为这需要更多空间。

您能否尝试从您的 ubuntu 虚拟机运行以下 python 程序并报告结果:

import requests;
print(requests.get('https://www.howsmyssl.com/a/check', verify=False).json()['tls_version']);

编辑

好的,这不是问题,尽管您可以提出请求。您可以对 requests 和 Twilio 端点做同样的事情吗?比如:

import requests;
request = requests.get('https://api.twilio.com/2010-04-01/Accounts/YOUR_ACCOUNT_SID/Messages.json', auth=('YOUR_ACCOUNT_SID', 'YOUR_AUTH_TOKEN'));
print request.json();

【讨论】:

  • 我收到此响应 InsecureRequestWarning: Unverified HTTPS request is made。强烈建议添加证书验证。请参阅:urllib3.readthedocs.io/en/latest/…InsecureRequestWarning) TLS 1.2
  • 它说了什么?
  • 为什么,仅使用该程序,您会发出不安全的请求?您是否有一些环境设置会影响您的 HTTP 请求?
  • 我没有做任何明确的设置。删除 verify=False 后,上述警告消失了
  • 啊!抱歉,我错过了verify=False 部分:D 好的,这意味着这不是问题。
【解决方案2】:

这是关于通过http服务器发送请求的,我也收到了这个错误

答案可在https://help.pythonanywhere.com/pages/TwilioBehindTheProxy获得

import os
from twilio.rest import Client
from twilio.http.http_client import TwilioHttpClient

proxy_client = TwilioHttpClient(proxy={'http': os.environ['http_proxy'], 'https': os.environ['https_proxy']})

account_sid = 'your account id here'
auth_token = 'your twilio token here'

client = Client(account_sid, auth_token, http_client=proxy_client)

# twilio api calls will now work from behind the proxy:
message = client.messages.create(to="...", from_='...', body='...')

【讨论】:

    猜你喜欢
    • 2020-10-31
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-18
    • 2022-10-31
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多