Solve “error_message”: “‘WSGIRequest’ object has no attribute ‘items’”


When you need to pass “request” into some instance, maybe on Django-haystack or some another django apps, somehow you got this kind of error :

1
2
"error_message": "’WSGIRequest’ object has no attribute ‘items’",
"traceback": "Traceback (most recent call last):nn File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py", line 192, in wrappern response = callback(request, *args, **kwargs)nn File "/home/vagrant/htdocs/ff/airport/../airport/services/api.py", line 61, in get_searchn page = paginator.page()nn File "/usr/local/lib/python2.7/dist-packages/tastypie/paginator.py", line 164, in pagen meta[‘previous’] = self.get_previous(limit, offset)nn File "/usr/local/lib/python2.7/dist-packages/tastypie/paginator.py", line 123, in get_previousn return self._generate_uri(limit, offset-limit)nn File "/usr/local/lib/python2.7/dist-packages/tastypie/paginator.py", line 139, in _generate_urin request_params = dict([k, v.encode(‘utf-8’)] for k, v in self.request_data.items())nnAttributeError: ‘WSGIRequest’ object has no attribute ‘items’n"


Actually, this is not difficult problem, because what the function need usually just dictionary of GET. So, if you need to pass request, try with request.GET. For instance :

1
paginator = Paginator(request.GET, …)

Problem solved! 😀


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.