Still having "__init__() keywords must be strings" in python2.7 - ReviewBoard

e141757 picture e141757 · Jan 30, 2015 · Viewed 7.5k times · Source

I'm trying to install ReviewBoard(https://www.reviewboard.org/) and I stuck with "init() keywords must be strings" problem when I was running it.

I read that it is common problem in python2.6. I've checked that and I had python2.6, so I installed python2.7, but the problem is still there.

[Fri Jan 30 16:02:11 2015] [error] mod_wsgi (pid=12875): Exception occurred processing WSGI script '/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py'.
[Fri Jan 30 16:02:11 2015] [error] Traceback (most recent call last):
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/wsgi.py", line 187, in __call__
[Fri Jan 30 16:02:11 2015] [error]     self.load_middleware()
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/core/handlers/base.py", line 45, in load_middleware
[Fri Jan 30 16:02:11 2015] [error]     mw_class = import_by_path(middleware_path)
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/utils/module_loading.py", line 21, in import_by_path
[Fri Jan 30 16:02:11 2015] [error]     module = import_module(module_path)
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/utils/importlib.py", line 40, in import_module
[Fri Jan 30 16:02:11 2015] [error]     __import__(name)
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/ReviewBoard-2.0.12-py2.7.egg/reviewboard/admin/middleware.py", line 23, in <module>
[Fri Jan 30 16:02:11 2015] [error]     from reviewboard.admin.checks import check_updates_required
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/ReviewBoard-2.0.12-py2.7.egg/reviewboard/admin/checks.py", line 41, in <module>
[Fri Jan 30 16:02:11 2015] [error]     from djblets.siteconfig.models import SiteConfiguration
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Djblets-0.8.14-py2.7.egg/djblets/siteconfig/models.py", line 28, in <module>
[Fri Jan 30 16:02:11 2015] [error]     from django.contrib.sites.models import Site
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/contrib/sites/models.py", line 58, in <module>
[Fri Jan 30 16:02:11 2015] [error]     class Site(models.Model):
[Fri Jan 30 16:02:11 2015] [error]   File "/usr/local/lib/python2.7/site-packages/Django-1.6.10-py2.7.egg/django/db/models/base.py", line 96, in __new__
[Fri Jan 30 16:02:11 2015] [error]     new_class.add_to_class('_meta', Options(meta, **kwargs))
[Fri Jan 30 16:02:11 2015] [error] TypeError: Error when calling the metaclass bases
[Fri Jan 30 16:02:11 2015] [error]     __init__() keywords must be strings

What I should mention is that python2.6 is still installed, so maybe here is the problem? In apache config file I am pointing to the python2.7, if I remove that line it is using python2.6.

WSGIDaemonProcess example.com python-path=/srv/www/htdocs/tools/reviewboard/htdocs:/usr/local/lib/python2.7/site-packages

I was also trying to use:

WSGIPythonHome /usr/local/lib/python2.7
WSGIPythonPath /usr/local/lib/python2.7

but then it gives me:

[Fri Jan 30 17:01:38 2015] [error]  mod_wsgi (pid=11500): Target WSGI script '/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py' cannot be loaded as Python module.
[Fri Jan 30 17:01:38 2015] [error]  mod_wsgi (pid=11500): Exception occurred processing WSGI script '/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py'.
[Fri Jan 30 17:01:38 2015] [error] Traceback (most recent call last):
[Fri Jan 30 17:01:38 2015] [error]   File "/srv/www/htdocs/tools/reviewboard/htdocs/reviewboard.py", line 3, in <module>
[Fri Jan 30 17:01:38 2015] [error]     import pkg_resources
[Fri Jan 30 17:01:38 2015] [error] ImportError: No module named pkg_resources

Reinstaling setup tools(https://pypi.python.org/pypi/setuptools) doesn't help

And when I run python2.7 or python2.6 form console and I import pkg_resources there is no error.

Do you have any ideas what have gone wrong here?

Answer

Two-Bit Alchemist picture Two-Bit Alchemist · Jan 30, 2015

This error is produced as follows (this is Python 2.7.9 but it doesn't matter that much).

def function(*args, **kwargs):
    print u'I got args: %s' % u', '.join(args)
    print u'I got kwrgs: %s' % u', '.join(u'%s=%s' % (k, v)
                                          for k, v in kwargs.items())

This function will print out whatever we pass it. In Python, we can specify keyword args manually, or unpack a dict. Let's unpack a dict.

kwargs = {'a': 1, 'b': 2}
function(**kwargs)
I got args: 
I got kwargs: a=1, b=2

Everything is kosher. However, dicts are more flexible and accept any hashable type as a key, not just strings. What happens if we do this?

kwargs[(0, 1)] = 'five'    # tuples are hashable and can be dict keys

Now, if we call function:

function(**kwargs)

We get:

TypeError: function() keywords must be strings

Because it is trying to unpack into function(a=1, b=2, (0, 1)='five'), which of course makes no sense.

Hope this helps.