0

我在 python 代码中遇到证书错误,如下在 docker 容器中运行laudio/pyodbc

  File "/usr/local/lib/python3.7/site-packages/fredapi/fred.py", line 131, in get_series
    root = self.__fetch_data(url)
  File "/usr/local/lib/python3.7/site-packages/fredapi/fred.py", line 64, in __fetch_data
    response = urlopen(url)
  File "/usr/local/lib/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.7/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.7/urllib/request.py", line 543, in _open
    '_open', req)
  File "/usr/local/lib/python3.7/urllib/request.py", line 503, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.7/urllib/request.py", line 1362, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/local/lib/python3.7/urllib/request.py", line 1321, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>

我的证书是最新的

root@8a03fe8175b7:/# pip install --upgrade certifi
Requirement already up-to-date: certifi in /usr/local/lib/python3.7/site-packages (2020.4.5.1)

我也尝试使用没有帮助的no_ssl_verification 解决方案。

另外,这个文件是空的,这意味着什么吗?在我的主机上它已满

root@2927b5836cfa:/# ls -alt /etc/ssl/certs/ca-certificates.crt 
-rw-r--r-- 1 root root 0 May 23 20:14 /etc/ssl/certs/ca-certificates.crt

来自容器中的 python shell 的更多信息,我不知道这是否有帮助。但是容器中没有 /export 目录:

print(ssl.get_default_verify_paths())

DefaultVerifyPaths(cafile=None, capath=None, openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/export/home/pb2/build/sb_0-35870562-1568195162.53/openssl-1.1.1d-el6-x86-64bit/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/export/home/pb2/build/sb_0-35870562-1568195162.53/openssl-1.1.1d-el6-x86-64bit/ssl/certs')

你能给我一些想法来解决这个问题吗?


Moodle - 配置文件更新后将新用户重定向到原始 URL (wantsurl)

我的在线课程的链接发布在各种网站上。链接如下所示:https ://example.com/course/view.php?id=31

当新用户点击链接时,他们会被带到我的 Moodle 网站登录页面。

当他们使用 Google 身份验证在我的 Moodle 网站上注册时,他们会被带到需要填写几个自定义字段的表单。

在他们填写自定义字段并提交后,他们将被带到preferences.php

而不是preferences.php,我需要它们转到存储在“wantsurl”中的原始URL

现在,我刚刚编辑了preferences.php 并使用了一个简单的重定向将用户发送到仪表板页面。

我可以在preferences.php 页面中添加什么代码来将用户重定向到他们想要访问的原始URL?即“wantsurl”

注意:如果我删除自定义字段,用户将在身份验证后重定向到课程页面 (wantsurl)。但是自定义字段是必不可少的。

4

1 回答 1

0

如果您的 docker 容器中没有安装 ca-certificates(即检查 /etc/ssl/certs 目录中是否存在各种证书),请先安装它们。

将以下行添加到 dockerfile 中解决了这个问题。

RUN apt-get update && \
    apt-get install ca-certificates -y && \
    apt-get clean
于 2021-05-07T11:32:14.473 回答