Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
requests.exceptions.SSLError-未能使用python模块_Python_Ssl_Openssl_Pip_Ssl Certificate - Fatal编程技术网

requests.exceptions.SSLError-未能使用python模块

requests.exceptions.SSLError-未能使用python模块,python,ssl,openssl,pip,ssl-certificate,Python,Ssl,Openssl,Pip,Ssl Certificate,我正在使用通过pypi.org/project/udemy-dl安装的python模块udemy-dl。当我运行脚本时,我不断收到一个SSL错误。我已经研究了许多关于Stackoverflow的问题,但似乎没有一个有效。我在终端上获得以下信息: [INFO-835] Downloading to: /Users/dev/the-complete-python-web-course-learn-by-building-8-apps [INFO-107] Trying to log in ...

我正在使用通过pypi.org/project/udemy-dl安装的python模块udemy-dl。当我运行脚本时,我不断收到一个SSL错误。我已经研究了许多关于Stackoverflow的问题,但似乎没有一个有效。我在终端上获得以下信息:

[INFO-835] Downloading to: /Users/dev/the-complete-python-web-course-learn-by-building-8-apps

[INFO-107] Trying to log in ...
Traceback (most recent call last):
  File "/Users/dev/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/Users/dev/homebrew/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/dev/homebrew/lib/python2.7/site-packages/udemy_dl/dev.py", line 8, in <module>
    main()
  File "/Users/dev/homebrew/lib/python2.7/site-packages/udemy_dl/udemy_dl.py", line 837, in main
    udemy_dl(username, password, link, lecture_start, lecture_end, save_links, safe_file_names, just_list, output_dest)
  File "/Users/dev/homebrew/lib/python2.7/site-packages/udemy_dl/udemy_dl.py", line 658, in udemy_dl
    login(username, password)
  File "/Users/dev/homebrew/lib/python2.7/site-packages/udemy_dl/udemy_dl.py", line 109, in login
    csrf_token = get_csrf_token()
  File "/Users/dev/homebrew/lib/python2.7/site-packages/udemy_dl/udemy_dl.py", line 95, in get_csrf_token
    response = session.get('https://www.udemy.com/join/login-popup')
  File "/Users/dev/homebrew/lib/python2.7/site-packages/udemy_dl/udemy_dl.py", line 66, in get
    return self.session.get(url, headers=self.headers)
  File "/Users/dev/homebrew/lib/python2.7/site-packages/requests/sessions.py", line 488, in get
    return self.request('GET', url, **kwargs)
  File "/Users/dev/homebrew/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/dev/homebrew/lib/python2.7/site-packages/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/Users/dev*emphasized text*/homebrew/lib/python2.7/site-packages/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)
我看到adapters.py中出现了异常:

def send(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
        """Sends PreparedRequest object. Returns Response object.

        :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
        :param stream: (optional) Whether to stream the request content.
        :param timeout: (optional) How long to wait for the server to send
            data before giving up, as a float, or a :ref:`(connect timeout,
            read timeout) <timeouts>` tuple.
        :type timeout: float or tuple
        :param verify: (optional) Whether to verify SSL certificates.
        :param cert: (optional) Any user-provided SSL certificate to be trusted.
        :param proxies: (optional) The proxies dictionary to apply to the request.
        :rtype: requests.Response
        """

        conn = self.get_connection(request.url, proxies)

        self.cert_verify(conn, request.url, verify, cert)
        url = self.request_url(request, proxies)
        self.add_headers(request)

        chunked = not (request.body is None or 'Content-Length' in request.headers)

        if isinstance(timeout, tuple):
            try:
                connect, read = timeout
                timeout = TimeoutSauce(connect=connect, read=read)
            except ValueError as e:
                # this may raise a string formatting error.
                err = ("Invalid timeout {0}. Pass a (connect, read) "
                       "timeout tuple, or a single float to set "
                       "both timeouts to the same value".format(timeout))
                raise ValueError(err)
        else:
            timeout = TimeoutSauce(connect=timeout, read=timeout)

        try:
            if not chunked:
                resp = conn.urlopen(
                    method=request.method,
                    url=url,
                    body=request.body,
                    headers=request.headers,
                    redirect=False,
                    assert_same_host=False,
                    preload_content=False,
                    decode_content=False,
                    retries=self.max_retries,
                    timeout=timeout
                )

            # Send the request.
            else:
                if hasattr(conn, 'proxy_pool'):
                    conn = conn.proxy_pool

                low_conn = conn._get_conn(timeout=DEFAULT_POOL_TIMEOUT)

                try:
                    low_conn.putrequest(request.method,
                                        url,
                                        skip_accept_encoding=True)

                    for header, value in request.headers.items():
                        low_conn.putheader(header, value)

                    low_conn.endheaders()

                    for i in request.body:
                        low_conn.send(hex(len(i))[2:].encode('utf-8'))
                        low_conn.send(b'\r\n')
                        low_conn.send(i)
                        low_conn.send(b'\r\n')
                    low_conn.send(b'0\r\n\r\n')

                    # Receive the response from the server
                    try:
                        # For Python 2.7+ versions, use buffering of HTTP
                        # responses
                        r = low_conn.getresponse(buffering=True)
                    except TypeError:
                        # For compatibility with Python 2.6 versions and back
                        r = low_conn.getresponse()

                    resp = HTTPResponse.from_httplib(
                        r,
                        pool=conn,
                        connection=low_conn,
                        preload_content=False,
                        decode_content=False
                    )
                except:
                    # If we hit any problems here, clean up the connection.
                    # Then, reraise so that we can handle the actual exception.
                    low_conn.close()
                    raise

        except (ProtocolError, socket.error) as err:
            raise ConnectionError(err, request=request)

        except MaxRetryError as e:
            if isinstance(e.reason, ConnectTimeoutError):
                # TODO: Remove this in 3.0.0: see #2811
                if not isinstance(e.reason, NewConnectionError):
                    raise ConnectTimeout(e, request=request)

            if isinstance(e.reason, ResponseError):
                raise RetryError(e, request=request)

            if isinstance(e.reason, _ProxyError):
                raise ProxyError(e, request=request)

            raise ConnectionError(e, request=request)

        except ClosedPoolError as e:
            raise ConnectionError(e, request=request)

        except _ProxyError as e:
            raise ProxyError(e)

        except (_SSLError, _HTTPError) as e:
            if isinstance(e, _SSLError):
                raise SSLError(e, request=request)

您使用的脚本将与主站点验证某些证书,并且仅在验证证书时才允许连接。可能的解决办法

一,。您需要下载网站提供的证书,并将其传递给调用verify='path/to/ssl/certificate/'或


二,。在脚本中找到请求调用并设置verify=False

选项verify在adapters.py和sessions.py中的许多位置。此错误在adapters.py中引发。我已将验证选项更改为False,但仍然会出现相同的错误