Anaconda的requests模板引入后,使用get方法报错的解决办法.pycharm和vscode通用

Anaconda 中的requests模块引入成功,但是requests.get确无法使用的解决办法


import requests temp=requests.get('https://www.baidu.com')
print(temp.text)

image-20210308023205904

报错信息:

D:\ProgramFiles\Anaconda3\python.exe "D:/Program Files (x86)/Python/PythonWorkPlace/studyPython/requests测试/test1.py"
Traceback (most recent call last):
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 588, in urlopen
    conn = self._get_conn(timeout=pool_timeout)
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 248, in _get_conn
    return conn or self._new_conn()
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 816, 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 "D:\ProgramFiles\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='unsplash.com', port=443): Max retries exceeded with url: / (Caused by 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 "D:/Program Files (x86)/Python/PythonWorkPlace/studyPython/requests测试/test1.py", line 2, in <module>
    temp=requests.get('https://unsplash.com')
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "D:\ProgramFiles\Anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='unsplash.com', port=443): Max retries exceeded with url: / (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

解决方法:

没有正确配置Anaconda的环境变量

D:\ProgramFiles\Anaconda3 
D:\ProgramFiles\Anaconda3\Scripts 
D:\ProgramFiles\Anaconda3\Library\bin #这个一定要配置

将Anaconda这三个位置添加到你电脑的环境变量中,位置要正确,这里只是我的路径.

image-20210308023511704

问题解决!

版权声明:
作者:单龙网
链接:https://www.danlong360.com/jiaochengziyuan/jishujiaocheng/anaconda%e7%9a%84requests%e6%a8%a1%e6%9d%bf%e5%bc%95%e5%85%a5%e5%90%8e%e4%bd%bf%e7%94%a8get%e6%96%b9%e6%b3%95%e6%8a%a5%e9%94%99%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95-pycharm%e5%92%8cvscode.html
来源:单龙网
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>