superset icon indicating copy to clipboard operation
superset copied to clipboard

Failed to execute 'superset load_examples ' , ssl.SSLError

Open sunnysnowhi opened this issue 6 years ago • 6 comments

I install the superset in CentOS, and when I execute the 'superset load_examples ', I have the error below: image

ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:777)

My CentOS is under company network which can not connect the Internet. I don't know whether this cause the error. If yes, is there a way to load examples without connect Internet?

Thank you very much!

sunnysnowhi avatar Mar 27 '20 01:03 sunnysnowhi

Anyone help?

sunnysnowhi avatar Mar 30 '20 01:03 sunnysnowhi

Hi @sunnysnowhi - the system loads examples from the internet, unfortunately. I'm not aware of another way to load examples.

willbarrett avatar Apr 01 '20 17:04 willbarrett

hi @willbarrett I set a proxy in /etc/profile in my CentOS , and now the server can connect internet and wget https://xxx can work properly. But when I execute superset load_examples , the error still exists, so I guess it is not the network problem...

Does anyone known how to solve it?

(superset-venv) [root@cn-north-5a-modelarts-insight superset-venv]# superset load_examples 2020-04-16 14:53:10,454:INFO:root:logging was configured successfully 2020-04-16 14:53:10,505:INFO:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'> Loading examples metadata and related data into examples Creating default CSS templates Loading energy related dataset 2020-04-16 14:53:11,738:INFO:root:Database.get_sqla_engine(). Masked URL: sqlite:////root/.superset/superset.db Traceback (most recent call last): File "/usr/local/python3/lib/python3.6/urllib/request.py", line 1318, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/usr/local/python3/lib/python3.6/http/client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/python3/lib/python3.6/http/client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/python3/lib/python3.6/http/client.py", line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/python3/lib/python3.6/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/local/python3/lib/python3.6/http/client.py", line 964, in send self.connect() File "/usr/local/python3/lib/python3.6/http/client.py", line 1400, in connect server_hostname=server_hostname) File "/usr/local/python3/lib/python3.6/ssl.py", line 407, in wrap_socket _context=self, _session=session) File "/usr/local/python3/lib/python3.6/ssl.py", line 814, in init self.do_handshake() File "/usr/local/python3/lib/python3.6/ssl.py", line 1068, in do_handshake self._sslobj.do_handshake() File "/usr/local/python3/lib/python3.6/ssl.py", line 689, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/superset-venv/bin/superset", line 31, in cli() File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 722, in call return self.main(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/flask/cli.py", line 586, in main return super(FlaskGroup, self).main(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/flask/cli.py", line 426, in decorator return __ctx.invoke(f, *args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/superset/cli.py", line 142, in load_examples load_examples_run(load_test_data, only_metadata, force) File "/opt/superset-venv/lib/python3.6/site-packages/superset/cli.py", line 83, in load_examples_run examples.load_energy(only_metadata, force) File "/opt/superset-venv/lib/python3.6/site-packages/superset/examples/energy.py", line 39, in load_energy data = get_example_data("energy.json.gz") File "/opt/superset-venv/lib/python3.6/site-packages/superset/examples/helpers.py", line 73, in get_example_data content = request.urlopen(f"{BASE_URL}{filepath}?raw=true").read() File "/usr/local/python3/lib/python3.6/urllib/request.py", line 223, in urlopen return opener.open(url, data, timeout) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 526, in open response = self._open(req, data) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 544, in _open '_open', req) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 504, in _call_chain result = func(*args) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 1361, in https_open context=self._context, check_hostname=self._check_hostname) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 1320, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:777)>

sunnysnowhi avatar Apr 16 '20 08:04 sunnysnowhi

sorry I fond my proxy was in wrong config, After fix the proxy, the problem unknown protocol is solved~~~~

Now I meet the new error: (superset-venv) [root@cn-north-5a-modelarts-insight superset-venv]# superset load_examples 2020-04-16 16:25:07,995:INFO:root:logging was configured successfully 2020-04-16 16:25:08,045:INFO:root:Configured event logger of type <class 'superset.utils.log.DBEventLogger'> Loading examples metadata and related data into examples Creating default CSS templates Loading energy related dataset 2020-04-16 16:25:09,251:INFO:root:Database.get_sqla_engine(). Masked URL: sqlite:////root/.superset/superset.db Traceback (most recent call last): File "/usr/local/python3/lib/python3.6/urllib/request.py", line 1318, in do_open encode_chunked=req.has_header('Transfer-encoding')) File "/usr/local/python3/lib/python3.6/http/client.py", line 1239, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/local/python3/lib/python3.6/http/client.py", line 1285, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/local/python3/lib/python3.6/http/client.py", line 1234, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/python3/lib/python3.6/http/client.py", line 1026, in _send_output self.send(msg) File "/usr/local/python3/lib/python3.6/http/client.py", line 964, in send self.connect() File "/usr/local/python3/lib/python3.6/http/client.py", line 1400, in connect server_hostname=server_hostname) File "/usr/local/python3/lib/python3.6/ssl.py", line 407, in wrap_socket _context=self, _session=session) File "/usr/local/python3/lib/python3.6/ssl.py", line 814, in init self.do_handshake() File "/usr/local/python3/lib/python3.6/ssl.py", line 1068, in do_handshake self._sslobj.do_handshake() File "/usr/local/python3/lib/python3.6/ssl.py", line 689, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/superset-venv/bin/superset", line 31, in cli() File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 722, in call return self.main(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/flask/cli.py", line 586, in main return super(FlaskGroup, self).main(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/flask/cli.py", line 426, in decorator return __ctx.invoke(f, *args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/opt/superset-venv/lib/python3.6/site-packages/superset/cli.py", line 142, in load_examples load_examples_run(load_test_data, only_metadata, force) File "/opt/superset-venv/lib/python3.6/site-packages/superset/cli.py", line 83, in load_examples_run examples.load_energy(only_metadata, force) File "/opt/superset-venv/lib/python3.6/site-packages/superset/examples/energy.py", line 39, in load_energy data = get_example_data("energy.json.gz") File "/opt/superset-venv/lib/python3.6/site-packages/superset/examples/helpers.py", line 73, in get_example_data content = request.urlopen(f"{BASE_URL}{filepath}?raw=true").read() File "/usr/local/python3/lib/python3.6/urllib/request.py", line 223, in urlopen return opener.open(url, data, timeout) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 526, in open response = self._open(req, data) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 544, in _open '_open', req) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 504, in _call_chain result = func(*args) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 1361, in https_open context=self._context, check_hostname=self._check_hostname) File "/usr/local/python3/lib/python3.6/urllib/request.py", line 1320, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

sunnysnowhi avatar Apr 16 '20 08:04 sunnysnowhi

I found the solution!

vim /opt/superset-venv/lib/python3.6/site-packages/superset/examples/helpers.py and change the way of urlopen:

before change: content = request.urlopen(f"{BASE_URL}{filepath}?raw=true").read()

after change: import ssl context = ssl._create_unverified_context() content = request.urlopen(f"{BASE_URL}{filepath}?raw=true", context=context).read()

image

The error above disappear, yeah~

sunnysnowhi avatar Apr 17 '20 06:04 sunnysnowhi

@sunnysnowhi The code has been changed in the latest version, but there is still this error, I do not know how to modify the code in the aspect of code formation, please advise, the code is as follows:

import json import os from typing import Any

from superset import app, db from superset.connectors.sqla.models import SqlaTable from superset.models.slice import Slice

BASE_URL = "https://github.com/apache-superset/examples-data/blob/master/"

misc_dash_slices: set[str] = set() # slices assembled in a 'Misc Chart' dashboard

def get_table_connector_registry() -> Any: return SqlaTable

def get_examples_folder() -> str: return os.path.join(app.config["BASE_DIR"], "examples")

def update_slice_ids(pos: dict[Any, Any]) -> list[Slice]: """Update slice ids in position_json and return the slices found.""" slice_components = [ component for component in pos.values() if isinstance(component, dict) and component.get("type") == "CHART" ] slices = {} for name in {component["meta"]["sliceName"] for component in slice_components}: slc = db.session.query(Slice).filter_by(slice_name=name).first() if slc: slices[name] = slc for component in slice_components: slc = slices.get(component["meta"]["sliceName"]) if slc: component["meta"]["chartId"] = slc.id component["meta"]["uuid"] = str(slc.uuid) return list(slices.values())

def merge_slice(slc: Slice) -> None: o = db.session.query(Slice).filter_by(slice_name=slc.slice_name).first() if o: db.session.delete(o) db.session.add(slc) db.session.commit()

def get_slice_json(defaults: dict[Any, Any], **kwargs: Any) -> str: defaults_copy = defaults.copy() defaults_copy.update(kwargs) return json.dumps(defaults_copy, indent=4, sort_keys=True)

def get_example_url(filepath: str) -> str: return f"{BASE_URL}{filepath}?raw=true"

Bc-Aqr avatar Sep 21 '23 07:09 Bc-Aqr