matomo-log-analytics icon indicating copy to clipboard operation
matomo-log-analytics copied to clipboard

When importing logs, if --url= is set to HTTP url and Piwik is forced to use SSL then importing logs fails

Open mattab opened this issue 9 years ago • 5 comments

When importing logs in Piwik and when Piwik is configured to use SSL by default, if you specify --url=http://piwik.example.org then Piwik will fail with this error:

2014-11-20 11:40:10,643: [DEBUG] Error when connecting to Piwik: <urlopen error Piwik returned an invalid response: <!DOCTYPE html>

The solution is to set the --url parameter to https://.... when importing logs.

To fix this issue, we could maybe detect the URL redirect from HTTP to HTTPS and make Log importer detect that HTTPS should be used.

Migrated from piwik/piwik#6699

mattab avatar Nov 19 '14 22:11 mattab

With https I get this. Error when connecting to Piwik: < urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) >

NA7KR avatar Dec 10 '15 05:12 NA7KR

With Python 2.7.9 release the default HTTPS behaviour has changed, which is now to always verify the remote HTTPS certificate to which you are initiating a connection.

Workaround: You have to edit import_logs.py

After "import textwrap" add this:

import ssl
try:     
    _create_unverified_https_context = ssl._create_unverified_context 
except AttributeError:     
    # Legacy Python that doesn't verify HTTPS certificates by default  
    pass 
else:     
    # Handle target environment that doesn't support HTTPS verification     
    ssl._create_default_https_context = _create_unverified_https_context

@mattab: Maybe you should implement an option to disable TLS cert checking.

shellshocker avatar Apr 08 '16 16:04 shellshocker

Hi @shellshocker - if you could open a Pull request, it would be very welcome!

mattab avatar Apr 21 '16 04:04 mattab

This issue was not fixed: if force_ssl=1 in the config.ini.php then importing the logs specifying HTTP:// will not work.

mattab avatar Dec 11 '17 20:12 mattab

Just revisited Piwik after several months absence - got further with installation this time, however I cannot import log files (JS is not an option).

Our site uses HTTPS (with HTTP being redirected to HTTPS).

Neither --url=http://site.com nor --url=https://site.com works. I always get the error:

[INFO] Error when connecting to Piwik: <urlopen error Piwik returned an invalid response: <!DOCTYPE html> ...and it proceeds to dump the HTML from the site.

Let me know if there's something I can try/tweak or provide any other feedback. Happy to help. Just want to get this baby to work :-(

ghost avatar Jan 03 '18 10:01 ghost