我在Python中使用REST apis。我收到了SSL错误

时间:2015-07-07 04:15:01

标签: python rest ssl python-requests python-3.4

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.p
y", line 533, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.p
y", line 246, in _get_conn
    return conn or self._new_conn()
  File "C:\Python34\lib\site-packages\requests\packages\urllib3\connectionpool.p
y", line 738, in _new_conn
    raise SSLError("Can't connect to HTTPS URL because the SSL "
requests.packages.urllib3.exceptions.SSLError: Can't connect to HTTPS URL becaus
e the SSL module is not available.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "hosts-print.py", line 19, in <module>
    host_count_response = requests.get(host_count_url, verify=False)
  File "C:\Python34\lib\site-packages\requests\api.py", line 69, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Python34\lib\site-packages\requests\api.py", line 50, in request
    response = session.request(method=method, url=url, **kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 465, in reques
t
    resp = self.send(prep, **send_kwargs)
  File "C:\Python34\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Python34\lib\site-packages\requests\adapters.py", line 431, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module
is not available.

在我向Google Chrome添加证书之前,我的代码工作正常。我重新安装了python和请求库,但代码只运行了一次。之后,同样的错误重复。

2 个答案:

答案 0 :(得分:0)

您需要手动指向.ca文件(添加verify = path_to_ca_file),否则您可以停用ssl verify = false

答案 1 :(得分:0)

卸载旧版本的Python,然后重新安装Python以及库并重新安装chrome(删除cookie,扩展和插件后)修复了问题。