我目前正在学习如何使用 pandas 库的教程,我可以解决这个错误。我对整个场景还是新手,所以我不完全确定发生了什么或如何解释这个错误:

----------------------------,python,ssl-certificate"/>
	














首页 > 解决方案 > Linux 上的 Jupyter:URL 错误:

我目前正在学习如何使用 pandas 库的教程,我可以解决这个错误。我对整个场景还是新手,所以我不完全确定发生了什么或如何解释这个错误:

----------------------------

问题描述

我目前正在学习如何使用 pandas 库的教程,我可以解决这个错误。我对整个场景还是新手,所以我不完全确定发生了什么或如何解释这个错误:

---------------------------------------------------------------------------
SSLCertVerificationError                  Traceback (most recent call last)
/snap/jupyter/6/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1316                 h.request(req.get_method(), req.selector, req.data, headers,
-> 1317                           encode_chunked=req.has_header('Transfer-encoding'))
   1318             except OSError as err: # timeout error

/snap/jupyter/6/lib/python3.7/http/client.py in request(self, method, url, body, headers, encode_chunked)
   1228         """Send a complete request to the server."""
-> 1229         self._send_request(method, url, body, headers, encode_chunked)
   1230 

/snap/jupyter/6/lib/python3.7/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
   1274             body = _encode(body, 'body')
-> 1275         self.endheaders(body, encode_chunked=encode_chunked)
   1276 

/snap/jupyter/6/lib/python3.7/http/client.py in endheaders(self, message_body, encode_chunked)
   1223             raise CannotSendHeader()
-> 1224         self._send_output(message_body, encode_chunked=encode_chunked)
   1225 

/snap/jupyter/6/lib/python3.7/http/client.py in _send_output(self, message_body, encode_chunked)
   1015         del self._buffer[:]
-> 1016         self.send(msg)
   1017 

/snap/jupyter/6/lib/python3.7/http/client.py in send(self, data)
    955             if self.auto_open:
--> 956                 self.connect()
    957             else:

/snap/jupyter/6/lib/python3.7/http/client.py in connect(self)
   1391             self.sock = self._context.wrap_socket(self.sock,
-> 1392                                                   server_hostname=server_hostname)
   1393 

/snap/jupyter/6/lib/python3.7/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
    411             context=self,
--> 412             session=session
    413         )

/snap/jupyter/6/lib/python3.7/ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
    852                         raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
--> 853                     self.do_handshake()
    854             except (OSError, ValueError):

/snap/jupyter/6/lib/python3.7/ssl.py in do_handshake(self, block)
   1116                 self.settimeout(None)
-> 1117             self._sslobj.do_handshake()
   1118         finally:

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
<ipython-input-3-dc8b64eb545d> in <module>
----> 1 df = pd.read_html('http://www.fdic.gov/bank/individual/failed/banklist.html')

/home/paul/snap/jupyter/common/lib/python3.7/site-packages/pandas/io/html.py in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, thousands, encoding, decimal, converters, na_values, keep_default_na, displayed_only)
   1098         na_values=na_values,
   1099         keep_default_na=keep_default_na,
-> 1100         displayed_only=displayed_only,
   1101     )

/home/paul/snap/jupyter/common/lib/python3.7/site-packages/pandas/io/html.py in _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs)
    893 
    894         try:
--> 895             tables = p.parse_tables()
    896         except ValueError as caught:
    897             # if `io` is an io-like object, check if it's seekable

/home/paul/snap/jupyter/common/lib/python3.7/site-packages/pandas/io/html.py in parse_tables(self)
    211         list of parsed (header, body, footer) tuples from tables.
    212         """
--> 213         tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
    214         return (self._parse_thead_tbody_tfoot(table) for table in tables)
    215         """

/home/paul/snap/jupyter/common/lib/python3.7/site-packages/pandas/io/html.py in _build_doc(self)
    731                     pass
    732             else:
--> 733                 raise e
    734         else:
    735             if not hasattr(r, "text_content"):

/home/paul/snap/jupyter/common/lib/python3.7/site-packages/pandas/io/html.py in _build_doc(self)
    712         try:
    713             if is_url(self.io):
--> 714                 with urlopen(self.io) as f:
    715                     r = parse(f, parser=parser)
    716             else:

/home/paul/snap/jupyter/common/lib/python3.7/site-packages/pandas/io/common.py in urlopen(*args, **kwargs)
    139     import urllib.request
    140 
--> 141     return urllib.request.urlopen(*args, **kwargs)
    142 
    143 

/snap/jupyter/6/lib/python3.7/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    220     else:
    221         opener = _opener
--> 222     return opener.open(url, data, timeout)
    223 
    224 def install_opener(opener):

/snap/jupyter/6/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
    529         for processor in self.process_response.get(protocol, []):
    530             meth = getattr(processor, meth_name)
--> 531             response = meth(req, response)
    532 
    533         return response

/snap/jupyter/6/lib/python3.7/urllib/request.py in http_response(self, request, response)
    639         if not (200 <= code < 300):
    640             response = self.parent.error(
--> 641                 'http', request, response, code, msg, hdrs)
    642 
    643         return response

/snap/jupyter/6/lib/python3.7/urllib/request.py in error(self, proto, *args)
    561             http_err = 0
    562         args = (dict, proto, meth_name) + args
--> 563         result = self._call_chain(*args)
    564         if result:
    565             return result

/snap/jupyter/6/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    501         for handler in handlers:
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:
    505                 return result

/snap/jupyter/6/lib/python3.7/urllib/request.py in http_error_302(self, req, fp, code, msg, headers)
    753         fp.close()
    754 
--> 755         return self.parent.open(new, timeout=req.timeout)
    756 
    757     http_error_301 = http_error_303 = http_error_307 = http_error_302

/snap/jupyter/6/lib/python3.7/urllib/request.py in open(self, fullurl, data, timeout)
    523             req = meth(req)
    524 
--> 525         response = self._open(req, data)
    526 
    527         # post-process response

/snap/jupyter/6/lib/python3.7/urllib/request.py in _open(self, req, data)
    541         protocol = req.type
    542         result = self._call_chain(self.handle_open, protocol, protocol +
--> 543                                   '_open', req)
    544         if result:
    545             return result

/snap/jupyter/6/lib/python3.7/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    501         for handler in handlers:
    502             func = getattr(handler, meth_name)
--> 503             result = func(*args)
    504             if result is not None:
    505                 return result

/snap/jupyter/6/lib/python3.7/urllib/request.py in https_open(self, req)
   1358         def https_open(self, req):
   1359             return self.do_open(http.client.HTTPSConnection, req,
-> 1360                 context=self._context, check_hostname=self._check_hostname)
   1361 
   1362         https_request = AbstractHTTPHandler.do_request_

/snap/jupyter/6/lib/python3.7/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
   1317                           encode_chunked=req.has_header('Transfer-encoding'))
   1318             except OSError as err: # timeout error
-> 1319                 raise URLError(err)
   1320             r = h.getresponse()
   1321         except:

URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>

我附上了整个东西以防万一。我运行了以下代码:

df = pd.read_html('http://www.fdic.gov/bank/individual/failed/banklist.html')

我已经看到了一些关于安装名为 certifi 的东西,但它说该要求已经得到满足。我目前正在运行 Ubuntu。我注意到这是 MacOS 上的一个突出错误,所以我不确定它是什么。

感谢您的时间!


将 mailgun 合并到控制器中

我一直在尝试使用mailgun。Node.js 响应一个获取请求,当我将它从我的routes文件中移出并进入控制器函数时,我知道我遗漏了一些东西。当我提出请求时它工作正常

const mailgun = require('mailgun.js');
const router = express.Router();

router.get('/', (req, res) => {
   const API_KEY = 'secret';
   const DOMAIN = 'secretdomain';
   const mg= mailgun({ apiKey: API_KEY, domain: DOMAIN });
   const data = {
     from: 'bob@thebuilder.com',
     to: 'barney@rubble.com',
     subject: 'Whats up doc',
     template: "reqfeedback",
   };
   mg.messages().send(data, function (error, body) {
    if (error) {
        console.log(error);
    }
    console.log(body);
   }); 
});

但是当我尝试将它作为一个函数添加到我的控制器文件中时,我得到一个未处理的 Promise TypeError 说mailgun is not a function 所以我确保它像这样包装在一个 try/catch 中......

controller.js

const mongoose = require('mongoose');
const mailgun = require('mailgun.js');

const sendEmail = async(req,res,next) => {
   try{
      const API_KEY = 'secret';
      const DOMAIN = 'secretdomain';
      const mg= mailgun({ apiKey: API_KEY, domain: DOMAIN });
      const data = {
          from: 'bob@thebuilder.com',
          to: 'barney@rubble.com',
          subject: 'Whats up doc',
          template: "reqfeedback",
      };
      await mg.messages().send(data, function (error, body) {
          if (error) {
            console.log(error);
       }
          console.log(body);
       });
  catch (err) {
    const error = new HttpError(
        'Something went wrong, could not send email.',
        500
    );
    return next(error);
    }
    res.status(200).json({ message: 'email sent' });
};

exports.sendEmail = sendEmail;

我添加了这条路线: routes.js

const controllers = require('../controllers/controllers');
const router = express.Router();
const express = require('express');

router.get('/sendEmail', controllers.sendEmail);

module.exports = router;

但是当我发送获取请求时,我不断收到 500 错误“消息”:“出了点问题,无法请求反馈。”

哈尔普请。

标签: pythonssl-certificate

解决方案


SSL 用于 https 协议,您尝试访问的链接使用不安全的 http,大多数应用程序会尝试让您远离 http 站点。尝试将“http://”更改为“https://”


推荐阅读