Python 请求(由 SSLError 引起(“无法连接到 HTTPS URL,因为 SSL 模块不可用。”)PyCharm 请求网站中的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54135206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Requests (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.") Error in PyCharm requesting website
提问by Frank Drin
Using requests in Python3 Windows via Pycharm, and receiving SSL Module Not Available Error
通过 Pycharm 在 Python3 Windows 中使用请求,并收到 SSL 模块不可用错误
I've spent hours trying to figure out what could be causing this. I've reinstalled Anaconda, and I am completely stuck. When running the following
我花了几个小时试图找出可能导致这种情况的原因。我已经重新安装了 Anaconda,但我完全卡住了。运行以下程序时
def Earlybird(daycount):
url = 'https://msft.com'
response = requests.get(url)
print(response)
Earlybird()
I receive the error
我收到错误
requests.exceptions.SSLError: HTTPSConnectionPool(host='msft.com',
port=443): Max retries exceeded with url: / (Caused by SSLError("Can't
connect to HTTPS URL because the SSL module is not available."))
I have no idea what could be causing this. As Anaconda is a recent install, I would assume everything would be up-to-date, so I'm unsure if this is pointing to the wrong SSL ? I am a bit new to python, so thanks for your patience. -
我不知道是什么原因造成的。由于 Anaconda 是最近安装的,我认为一切都是最新的,所以我不确定这是否指向错误的 SSL?我对 python 有点陌生,所以感谢您的耐心等待。——
回答by Paul Stevens
Don't know if this has been solved yet but I was getting similar problems with Anaconda python 3.7.3 and Idle on Windows 10. Fixed it by adding:
不知道这是否已经解决,但我在 Windows 10 上的 Anaconda python 3.7.3 和 Idle 上遇到了类似的问题。通过添加以下内容修复它:
<path>\Anaconda3
<path>\Anaconda3\scripts
<path>\Anaconda3\Library\bin
to the PATH variable.
到 PATH 变量。
回答by Pavel Karateev
I got it solved by installing OpenSSL according to the following recomendation: https://github.com/conda/conda/issues/8046#issuecomment-450515815
我根据以下建议通过安装 OpenSSL 解决了这个问题:https: //github.com/conda/conda/issues/8046#issuecomment-450515815
Corresponding ticket in the conda repo: https://github.com/conda/conda/issues/8046
conda repo中对应的ticket:https: //github.com/conda/conda/issues/8046
Update:the problem (in PyCharm) should be solved in 2019.1 version (Early Access Preview build is already available https://www.jetbrains.com/pycharm/nextversion/).
更新:问题(在 PyCharm 中)应该在 2019.1 版本中解决(Early Access Preview 版本已经可用https://www.jetbrains.com/pycharm/nextversion/)。
回答by Matt Dnv
I am on Windows 10, I had the problem with a new fresh installation of Anaconda on python 3.7.4, this post on github solved my problem:
我在 Windows 10 上,我在 python 3.7.4 上全新安装 Anaconda 时遇到了问题,github 上的这篇文章解决了我的问题:
( source: https://github.com/conda/conda/issues/8273)
(来源:https: //github.com/conda/conda/issues/8273)
I cite:
我引用:
" My workaround: I have copied the following files
" 我的解决方法:我已经复制了以下文件
libcrypto-1_1-x64.*
libssl-1_1-x64.*
from D:\Anaconda3\Library\bin to D:\Anaconda3\DLLs.
从 D:\Anaconda3\Library\bin 到 D:\Anaconda3\DLLs。
And it works as a charm! "
它是一种魅力!”
回答by Siddhu
I've installed the binaries from here: https://slproweb.com/products/Win32OpenSSL.htmlThis site is mentioned on the official OpenSSL wiki. It solved my problem
我已经从这里安装了二进制文件:https: //slproweb.com/products/Win32OpenSSL.html官方 OpenSSL wiki 上提到了该站点。它解决了我的问题
回答by Mukesh Methaniya
Windows Users need to set below paths:
Windows 用户需要设置以下路径:
..\Anaconda3
..\Anaconda3\scripts
..\Anaconda3\Library\bin
..\Anaconda3
..\Anaconda3\scripts
..\Anaconda3\Library\bin
Per user:
每个用户:
- Open Environment variable
- Click User Variable
- Close command prompt if already open and reopen it
- 打开环境变量
- 点击 User Variable
- 如果已经打开,请关闭命令提示符并重新打开它
System wide(requires restart):
系统范围(需要重新启动):
- Open Environment variable
- Click System Variable
- Restart Windows
- 打开环境变量
- 点击 System Variable
- 重新启动 Windows
回答by codeherk
I don't have Anaconda so the steps I took are:
我没有 Anaconda,所以我采取的步骤是:
brew uninstall python3
brew install python3
- got an error message stating,
Your Xcode (10.2) is too outdated. Please update to Xcode 11.3 (or delete it). Xcode can be updated from the App Store.
**So, I deleted Xcode since no update would show, then I reinstalled it. - ran
xcode-select --install
after. If you don't.. you'll get an error:The following formula python cannot be installed as binary package and must be built from source. Install the Command Line Tools: xcode-select --install
- got an error message stating,
- ran
brew install python3
and it completed successfully.
brew uninstall python3
brew install python3
- 收到一条错误消息,指出
Your Xcode (10.2) is too outdated. Please update to Xcode 11.3 (or delete it). Xcode can be updated from the App Store.
**因此,我删除了 Xcode,因为不会显示任何更新,然后我重新安装了它。 - 追了过去
xcode-select --install
。如果你不......你会得到一个错误:The following formula python cannot be installed as binary package and must be built from source. Install the Command Line Tools: xcode-select --install
- 收到一条错误消息,指出
- 运行
brew install python3
并成功完成。
Used this script just to see if it works
使用这个脚本只是为了看看它是否有效
import requests
r = requests.get('https://www.office.com')
print(r)
Ran the script python3 and python3.7 and output was <Response [200]>
instead of SSLError.
运行脚本 python3 和 python3.7,输出<Response [200]>
不是 SSLError。
回答by dhina karan
I have faced it on 04/2020. These are the options that I tried and the last solution get me through.
我在 04/2020 遇到了它。这些是我尝试过的选项,最后一个解决方案让我通过。
Problem:
问题:
Requests module works fine when I use in Spyder IDE but when I try to execute the script in windows it fails with SSL error. It works fine for HTTP requests but for HTTPS requests i got SSL error.
当我在 Spyder IDE 中使用时,请求模块工作正常,但是当我尝试在 Windows 中执行脚本时,它因 SSL 错误而失败。它适用于 HTTP 请求,但对于 HTTPS 请求,我收到 SSL 错误。
- I tired with Veify=True, False , also with Certs. Same error.
- Removed Certifi - conda remove certifi - Did not workUpdated
- openssl , certifi - Still same error( Refer : https://github.com/ContinuumIO/anaconda-issues/issues/494) Added
- the path variables - Same error
- Created new environment in Anaconda - same error
- 我厌倦了 Veify=True, False ,也厌倦了证书。同样的错误。
- 删除了证书 - conda remove certifi -不起作用更新
- openssl , certifi -仍然是同样的错误(参考:https: //github.com/ContinuumIO/anaconda-issues/issues/494)添加
- 路径变量 -同样的错误
- 在 Anaconda 中创建新环境 -同样的错误
Solution that fixed it:
修复它的解决方案:
Solution from: https://github.com/conda/conda/issues/8273
解决方案来自:https: //github.com/conda/conda/issues/8273
I have copied the following files from Anaconda3\Library\bin to \Anaconda3\DLL
我已将以下文件从 Anaconda3\Library\bin 复制到 \Anaconda3\DLL
libcrypto-1_1-x64.* libssl-1_1-x64.*
libcrypto-1_1-x64.* libssl-1_1-x64.*
回答by blah blah
this issue was driving me insane until i found this post which said to do
这个问题让我发疯,直到我发现这篇文章说要做
brew upgrade python3
(not using pycharm, using sublime)
(不使用pycharm,使用sublime)
回答by harryrobbins
I had a similar problem on Windows 10 using Conda and Python 2.7.2
我在使用 Conda 和 Python 2.7.2 的 Windows 10 上遇到了类似的问题
After trying many, many solutions I came across this responsewhich suggested that there is an issue with openssl in that build.
在尝试了很多很多解决方案之后,我遇到了这个响应,它表明该版本中的 openssl 存在问题。
Once I downgraded python to 3.7.1 (build h33f27b4_4) everything worked fine.
一旦我将 python 降级到 3.7.1(构建 h33f27b4_4),一切正常。
回答by sayth
There is no need to add paths to environment if you use the Anaconda Prompt.
如果您使用Anaconda Prompt,则无需添加环境路径。
Start the Anaconda prompt change to your directory and run your script or start your editor from there. This will ensure you are in the full Anaconda environment and the SSL error will stop.
启动 Anaconda 提示更改到您的目录并运行您的脚本或从那里启动您的编辑器。这将确保您处于完整的 Anaconda 环境中并且 SSL 错误将停止。
Whats the difference between command prompt and Anaconda Prompt?See this SO answer to what is the difference between command prompt and anaconda prompt.
命令提示符和 Anaconda 提示符有什么区别?请参阅此 SO 答案以了解 command prompt 和 anaconda prompt 之间的区别。