Trying to set up import_logs.py to communicate with Piwik served through Nginx, but it keeps failing with error Error when connecting to Piwik: .
I set up authentication when loading Piwik from the machine, but this doesn’t work with import_logs.py
. So instead, I set up a localhost-only port so the logs can be imported into the Piwik instance.
Here’s the relevant Nginx setup for the localhost-only Piwik port:
server {
listen 55557;
allow <machine IP>;
allow 127.0.0.1;
deny all;
root /var/www-stats/piwik;
index index.php index.html index.html;
access_log /var/log/nginx/localhost_access.log;
error_log /var/log/nginx/localhost_error.log info;
client_max_body_size 10m;
client_body_buffer_size 1024k;
# Try all locations and relay to index.php as a fallback.
# location / {
# try_files $uri /index.php;
# }
# Relay all index.php requests to fastcgi.
# location ~* ^/(?:index|piwik)\.php$ {
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}
That setup seems to work correctly:
> curl -I http://localhost:55557/piwik.php
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 17 Sep 2012 20:53:26 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.3.10
But the actual import fails:
> /var/www-stats/piwik/misc/log-analytics/import_logs.py -d --url=http://localhost:55557 --idsite=1 --recorders=1 --enable-http-errors --enable-http-redirects --enable-static --enable-bots access.log-20120916
2012-09-17 15:54:51,219: [DEBUG] Accepted hostnames: all
2012-09-17 15:54:51,219: [DEBUG] Piwik URL is: http://localhost:55557
2012-09-17 15:54:51,220: [DEBUG] No token-auth specified
2012-09-17 15:54:51,220: [DEBUG] No credentials specified, reading them from "/var/www-stats/piwik/config/config.ini.php"
2012-09-17 15:54:51,222: [DEBUG] Using credentials: (login = XXXXXX, password = YYYYYY)
2012-09-17 15:54:52,412: [DEBUG] Authentication token token_auth is: ZZZZZZ
2012-09-17 15:54:52,413: [DEBUG] Resolver: static
0 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
2012-09-17 15:54:52,654: [DEBUG] Launched recorder
Parsing log access.log-20120916...
2012-09-17 15:54:52,654: [DEBUG] Detecting the log format
2012-09-17 15:54:52,743: [DEBUG] Format ncsa_extended matches
2445 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
2012-09-17 15:54:53,781: [DEBUG] Error when connecting to Piwik: <urlopen error None>
4794 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
8206 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
2012-09-17 15:54:56,121: [DEBUG] Error when connecting to Piwik: <urlopen error None>
10362 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
12508 lines parsed, 0 lines recorded, 0 records/sec (avg), 0 records/sec (current)
2012-09-17 15:54:58,411: [DEBUG] Error when connecting to Piwik: <urlopen error None>
Fatal error: None
You can restart the import of "access.log-20120916" from the point it failed by specifying --skip=0 on the command line.
An error of “None” isn’t helpful.
Any ideas what I’m doing wrong?