matomo-org / matomo-log-analytics

Import any kind of server logs in Matomo for powerful log analytics. Universal log file parsing and reporting.
https://matomo.org/log-analytics/
GNU General Public License v3.0
224 stars 118 forks source link

Error when connecting to Matomo: <urlopen error [SSL: UNEXPECTED_MESSAGE] #300

Open deysumitkr opened 3 years ago

deysumitkr commented 3 years ago

Fresh install of Matomo On Ubuntu 20.04.1 LTS following official instructions

$ sudo python3 matomo/misc/log-analytics/import_logs.py --url=https://analytics.my.domain --idsite=1 /var/log/apache2/access.log.1
2021-01-16 23:57:56,969: [INFO] Error when connecting to Matomo: <urlopen error [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1123)>
2021-01-16 23:57:56,970: [INFO] Retrying request, attempt number 2
2021-01-16 23:58:07,081: [INFO] Error when connecting to Matomo: <urlopen error [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1123)>
2021-01-16 23:58:07,082: [INFO] Retrying request, attempt number 3
2021-01-16 23:58:17,184: [INFO] Error when connecting to Matomo: <urlopen error [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1123)>
2021-01-16 23:58:17,184: [INFO] Max number of attempts reached, server is unreachable!
Traceback (most recent call last):
  File "/usr/lib/python3.8/urllib/request.py", line 1350, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.8/http/client.py", line 950, in send
    self.connect()
  File "/usr/lib/python3.8/http/client.py", line 1424, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1123)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "matomo/misc/log-analytics/import_logs.py", line 1584, in _call_wrapper
    response = func(*args, **kwargs)
  File "matomo/misc/log-analytics/import_logs.py", line 1570, in _call_api
    res = self._call('/', final_args, url=url)
  File "matomo/misc/log-analytics/import_logs.py", line 1523, in _call
    response = opener.open(request, timeout = timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 1393, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/usr/lib/python3.8/urllib/request.py", line 1353, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1123)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "matomo/misc/log-analytics/import_logs.py", line 2669, in <module>
    resolver = config.get_resolver()
  File "matomo/misc/log-analytics/import_logs.py", line 1117, in get_resolver
    return StaticResolver(self.options.site_id)
  File "matomo/misc/log-analytics/import_logs.py", line 1648, in __init__
    site = matomo.call_api(
  File "matomo/misc/log-analytics/import_logs.py", line 1632, in call_api
    return self._call_wrapper(self._call_api, None, None, method, **kwargs)
  File "matomo/misc/log-analytics/import_logs.py", line 1621, in _call_wrapper
    raise MatomoHttpBase.Error(message, code)
__main__.Error: [SSL: UNEXPECTED_MESSAGE] unexpected message (_ssl.c:1123)
Findus23 commented 3 years ago

Hi,

It seems like your Python version can't understand the SSL your webserver sends. Which webserver are you using and which TLS versions do you have enabled?

deysumitkr commented 3 years ago

Hi, Server version: Apache/2.4.41 (Ubuntu) In ssl.conf: SSLProtocol all -SSLv3

On visiting matomo page from a web browser it shows TLS 1.3

$ openssl version -v
OpenSSL 1.1.1f  31 Mar 2020
$  python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.1.1f  31 Mar 2020 
mpichot commented 3 years ago

Hi, I get the same error here with TLSv1.3 certificate. The error is clear:

2021-08-25 17:36:19,651: [INFO] Error when connecting to Matomo: <urlopen error [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:877)>