requests.get()引发SSL错误

时间:2016-09-19 19:09:35

标签: python ssl python-requests

我在共享的FreeBSD主机上使用Python 2.7.3。 已安装的python请求模块版本为2.11.1。

import json
import requests
from requests.auth import HTTPBasicAuth
requests.packages.urllib3.disable_warnings()
s = requests.Session()
s.server = "dns-api.company.net"
s.auth = HTTPBasicAuth('user', 'pass')
s.headers = {'User-Agent':'DNS-Client'}
s.verify = False
r = s.get('https://dns-api.company.net/query') //Not the actual url

如您所见,我将verify设置为False。然而,我收到以下SSL错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 477, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno bad handshake] [('SSL routines', 'SSL23_GET_SERVER_HELLO', '')]

我尝试了以下变化,但无效,因为我最终得到了同样的错误。

from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

r = requests.get("https://dns-api.company.net/query", verify=False, auth=('user','pass')) // Dummy URL

我不关心SSL验证。我在这里做错了什么?

0 个答案:

没有答案