After upgrading piwik from 2.12.0 to 2.13.0 we get the following error when import apache logs using import_logs.py:
Traceback (most recent call last):
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 2159, in
config = Configuration()
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 822, in init
self._parse_args(self._create_parser())
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 805, in _parse_args
self.options.piwik_token_auth = self._get_token_auth()
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 841, in _get_token_auth
_url=self.options.piwik_url,
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 1252, in call_api
return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 1211, in _call_wrapper
response = func(*args, **kwargs)
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 1196, in _call_api
res = Piwik._call(’/’, final_args, url=url)
File “/var/www/html/piwik/misc/log-analytics/import_logs.py”, line 1157, in _call
response = urllib2.urlopen(request, timeout = config.options.request_timeout) NameError: global name ‘config’ is not defined
After further analyzing the issue we found the reason for the NameError:
When we start piwik, the global variable ‘config’ is used while defining it.
In import_logs.py line 2158 the definition is called: config = Configuration()
But while creating this object in import_logs.py line 1157 the
global variable ‘config’ is already used:
Hi Hula,
I am not sure if you really have the same issue.
Please verify if it is the variable config in the urlopen statement which causes the Problem.
As a Workaround we catch the Name error exception.
There we added the 3 lines
Try:
and
except Name error
and
Response = urllib2.urlopen(request)
like this:
try:
response = urllib2.urlopen(request, timeout = config.options.request_timeout)
except NameError:
response = urllib2.urlopen(request)
In the exception block we call the urlopen Statement without the config Parameter. In our case this Approach solves the issue.
Im on the latest version and that what i get since some days (havent check that due to work)
Traceback (most recent call last):
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 2159, in <module>
config = Configuration()
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 822, in __init__
self._parse_args(self._create_parser())
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 805, in _parse_args
self.options.piwik_token_auth = self._get_token_auth()
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 841, in _get_token_auth
_url=self.options.piwik_url,
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 1252, in call_api
return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 1211, in _call_wrapper
response = func(*args, **kwargs)
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 1196, in _call_api
res = Piwik._call('/', final_args, url=url)
File "/home/www/piwik/misc/log-analytics/import_logs.py", line 1157, in _call
response = urllib2.urlopen(request, timeout = config.options.request_timeout)
NameError: global name 'config' is not defined
Hi Hula,
you did not add all suggested lines:
try:
response = urllib2.urlopen(request, timeout = config.options.request_timeout)
except NameError:
response = urllib2.urlopen(request)
You forgot the line Try:. Also keep in mind that line indention is important in python.
Cheers
Hartmut
Still having this problem with the 2.16.2 version of piwik.
c:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py --url=https://myurl/Analytics/piwik/ c:\inetpub\wwwroot\Analytics\log1.log --login=xxxxxxxxxxx --password=xxxxxxxx --idsite=2 --enable-http-errors
2016-08-29 11:49:19,707: [INFO] Error when connecting to Piwik: HTTP Error 405: Method Not Allowed
Traceback (most recent call last):
File “C:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py”, line 2336, in
config = Configuration()
File “C:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py”, line 885, in init
self._parse_args(self._create_parser())
File “C:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py”, line 865, in _parse_args
self.options.piwik_token_auth = self._get_token_auth()
File “C:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py”, line 904, in _get_token_auth
_url=self.options.piwik_url,
File “C:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py”, line 1366, in call_api
return cls._call_wrapper(cls._call_api, None, None, method, **kwargs)
File “C:\inetpub\wwwroot\Analytics\piwik\misc\log-analytics\import_logs.py”, line 1350, in _call_wrapper
if errors == config.options.max_attempts:
NameError: global name ‘config’ is not defined
This is a brand new install. I don’t even know where to start on the fix for this any thoughts?