开发者社区> 问答> 正文

python中使用requests模块请求https的网站报错

代码如下


import requests

print(requests.get("https://www.baidu.com"))

错误提示如下,是什么原因造成的

Traceback (most recent call last):
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/urllib3/connectionpool.py", line 588, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/urllib3/connectionpool.py", line 250, in _get_conn
    return conn or self._new_conn()
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/urllib3/connectionpool.py", line 821, in _new_conn
    raise SSLError("Can't connect to HTTPS URL because the SSL "
urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jiangyd/PycharmProjects/untitled10/mm.py", line 12, in <module>
    print(requests.get("https://www.baidu.com"))
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/requests/sessions.py", line 502, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/requests/sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "/Users/jiangyd/python3_zy/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.

展开
收起
道月芬1 2021-10-19 12:39:21 1314 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。

    您好,请安装ssl相关模块(Py3)

    pip install pyopenssl
    
    2021-10-19 16:35:17
    赞同 1 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载