emsdk 安装失败,出现 urlopen 错误 [SSL: CERTIFICATE_VERIFY_FAILED]。

huangapple go评论72阅读模式
英文:

emsdk install fails with urlopen error [SSL: CERTIFICATE_VERIFY_FAILED]

问题

我正在尝试在 Windows 下根据这里的说明安装 emsdk。
我使用的是 Windows 10.0.19045.2728,是全新安装并已更新的,在一个具有开放互联网访问权限的虚拟机中。我以管理员身份安装了Python 3.11.3,并将其添加到了 PATH 中。然后,我下载了emsdk 2023-04-03并解压缩到一个 emsdk 文件夹中,然后在 cmd.exe 中执行以下命令:

> emsdk install latest

将 SDK 别名 'latest' 解析为 '3.1.35'
将 SDK 版本 '3.1.35' 解析为 'sdk-releases-671550b5bdceee7bdb21493714f9a815aa5149a9-64bit'
正在安装 SDK 'sdk-releases-671550b5bdceee7bdb21493714f9a815aa5149a9-64bit'..
正在安装工具 'node-14.18.2-64bit'..
错误: 下载 URL 'https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v14.18.2-win-x64.zip' 失败: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)>
警告: 可能是 SSL/TLS 问题。请更新或安装 Python 文件夹中提供的 2048 位或更高版本的 SSL 根证书,或访问 https://pypi.org/project/certifi/ 并重试。
错误: 安装失败!

我错过了什么?

我尝试过

  • pip install certifi(成功,但没有解决问题)
  • python emsdk.py install latest(没有变化)
  • 使用 Python 3.9.13(没有变化)
  • 在拥有相同网络访问权限的 Mint 21.1 虚拟机中(这个方法可行)

丑陋的解决方法:我成功地将以下补丁插入到 emsdk.pydownload_file 开头:

if url.startswith("https://storage.googleapis.com/"): # TODO fix/remove me
  url = "http"+url[5:]    # 将 https 更改为 http      # TODO fix/remove me
英文:

I'm trying to install emsdk under Windows according to instructions there.
I use Windows (10.0.19045.2728 freshly installed and updated, in a VM with open internet access). I install Python 3.11.3 (as admin with "Add python.exe to PATH"), download emsdk 2023-04-03 and unzip that to an emsdk folder, and in a cmd.exe prompt do

&gt; emsdk install latest
Resolving SDK alias &#39;latest&#39; to &#39;3.1.35&#39;
Resolving SDK version &#39;3.1.35&#39; to &#39;sdk-releases-671550b5bdceee7bdb21493714f9a815aa5149a9-64bit&#39;
Installing SDK &#39;sdk-releases-671550b5bdceee7bdb21493714f9a815aa5149a9-64bit&#39;..
Installing tool &#39;node-14.18.2-64bit&#39;..
Error: Downloading URL &#39;https://storage.googleapis.com/webassembly/emscripten-releases-builds/deps/node-v14.18.2-win-x64.zip&#39;: &lt;urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)&gt;
Warning: Possibly SSL/TLS issue. Update or install Python SSL root certificates (2048-bit or greater) supplied in Python folder or https://pypi.org/project/certifi/ and try again.
error: installation failed!

What am I missing?

I tried

  • pip install certifi (that succeeds, but does not cure it)
  • python emsdk.py install latest (no change)
  • using Python 3.9.13 (no change)
  • under a Mint 21.1 VM with the same network access (it worked)

Ugly workaround: I successfully inserted this kludge in emsdk.py at start of download_file

    if url.startswith(&quot;https://storage.googleapis.com/&quot;): # TODO fix/remove me
      url = &quot;http&quot;+url[5:]    # change https to http      # TODO fix/remove me

答案1

得分: 0

以下是代码的中文翻译:

赞扬yolw:运行他们的PowerShell脚本可以永久解决这个问题!稍作编辑:

# 这似乎会更新机器证书存储,以便Python可以按Emscripten的要求下载文件
$WebsiteURL = "storage.googleapis.com"
Try {
    $Conn = New-Object System.Net.Sockets.TcpClient($WebsiteURL, 443)

    Try {
        $Stream = New-Object System.Net.Security.SslStream($Conn.GetStream())
        $Stream.AuthenticateAsClient($WebsiteURL)
        $Cert = $Stream.Get_RemoteCertificate()
        $ValidTo = [datetime]::Parse($Cert.GetExpirationDatestring())

        Write-Host "`n连接成功" -ForegroundColor DarkGreen
        Write-Host "网站: $WebsiteURL"
        Write-Host "有效期至: $ValidTo"
    }
    Catch { Throw $_ }
    Finally { $Conn.close() }
}
Catch {
    Write-Host "`n连接到 $($WebsiteURL) 时发生错误" -ForegroundColor Yellow
    Write-Host "网站: $WebsiteURL"
    Write-Host "状态:" $_.exception.innerexception.message -ForegroundColor Yellow
    Write-Host ""
}

要将此保存为update-machine-certs.ps1,我需要执行以下命令:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

之后,我用以下命令撤销了设置:

Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser

输出如下:

连接成功
网站: storage.googleapis.com
有效期至: 06/12/2023 10:29:06
英文:

Kudos to yolw: running their powershell script fixes it for good! Slightly edited:

# This seems to update the machine cert store so that python can download the files as required by emscripten&#39;s install
$WebsiteURL=&quot;storage.googleapis.com&quot;
Try {
    $Conn = New-Object System.Net.Sockets.TcpClient($WebsiteURL,443) 
  
    Try {
        $Stream = New-Object System.Net.Security.SslStream($Conn.GetStream())
        $Stream.AuthenticateAsClient($WebsiteURL) 
        $Cert = $Stream.Get_RemoteCertificate()
        $ValidTo = [datetime]::Parse($Cert.GetExpirationDatestring())
   
        Write-Host &quot;`nConnection Successfull&quot; -ForegroundColor DarkGreen
        Write-Host &quot;Website: $WebsiteURL&quot;
        Write-Host &quot;ValidTo: $ValidTo&quot;
    }
    Catch { Throw $_ }
    Finally { $Conn.close() }
}
Catch {
    Write-Host &quot;`nError occurred connecting to $($WebsiteURL)&quot; -ForegroundColor Yellow
    Write-Host &quot;Website: $WebsiteURL&quot;
    Write-Host &quot;Status:&quot; $_.exception.innerexception.message -ForegroundColor Yellow
    Write-Host &quot;&quot;
}

To get this saved as update-machine-certs.ps1 running, I needed to issue

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser

that I undid with

Set-ExecutionPolicy -ExecutionPolicy Undefined    -Scope CurrentUser

The output was

Connection Successfull
Website: storage.googleapis.com
ValidTo: 06/12/2023 10:29:06

huangapple
  • 本文由 发表于 2023年4月11日 14:59:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983185.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定