Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Rendering error when displaying an agora #45

Closed
xaviarias opened this issue Sep 4, 2014 · 4 comments
Closed

Rendering error when displaying an agora #45

xaviarias opened this issue Sep 4, 2014 · 4 comments

Comments

@xaviarias
Copy link

Hello, I have a fresh development installation with SQL Lite and the last repository version (last commit "Allow anonymous authorization for login and register").

After creating an agora via web UI, the agora page generates the following error:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/xavi/test-agora-1

Django Version: 1.5.5
Python Version: 2.7.6
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.comments',
 'django.contrib.markup',
 'django.contrib.flatpages',
 'debug_toolbar',
 'south',
 'tastypie',
 'easy_thumbnails',
 'userena',
 'rosetta',
 'actstream',
 'social_auth',
 'crispy_forms',
 'agora_site.agora_core',
 'agora_site.accounts',
 'haystack',
 'captcha',
 'djcelery',
 'guardian',
 'djsgettext',
 'djangosecure')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'djangosecure.middleware.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'social_auth.middleware.SocialAuthExceptionMiddleware')


Template error:
In template /home/xavi/Desenvolupament/Codi/agora-ciudadana/agora_site/agora_core/templates/agora_core/agora_view.html, error at line 93
   'str' object has no attribute 'get'
   83 : {% include "agora_core/client/mail_to_members.html" %}


   84 : {% include "agora_core/client/tallied_elections_view.html" %}


   85 : {% include "agora_core/client/add_members_modal_dialog.html" %}


   86 : {% include "agora_core/client/send_mail.html" %}


   87 : {% include "agora_core/client/agora_tabs.html" %}


   88 : {% include "agora_core/client/agora_calendar.html" %}


   89 : <script>


   90 : var ajax_data = {


   91 :     'tallied_elections': {% rest request '/agora/' agora.id '/tallied_elections/?limit=3' %},


   92 :     'agora': {% rest request '/agora/' agora.id '/' %},


   93 :     'user_permissions':  {% custom_rest request "POST" '{"action":"get_permissions"}' '/agora/' agora.id '/action/' %} 


   94 : };


   95 : 


   96 : var current_tab = "{% block agora-tab-name %}activity{% endblock %}";


   97 : 


   98 : app.currentView = new Agora.AgoraView();


   99 : 


   100 : </script>


   101 : {% endblock %}


   102 : {% block footer %} {% endblock %}


   103 : 

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  140.                     response = response.render()
File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in render
  105.             self.content = self.rendered_content
File "/usr/local/lib/python2.7/dist-packages/django/template/response.py" in rendered_content
  82.         content = template.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py" in instrumented_test_render
  66.     return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  124.         return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py" in instrumented_test_render
  66.     return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  124.         return compiled_parent._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/test/utils.py" in instrumented_test_render
  66.     return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader_tags.py" in render
  63.             result = block.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py" in render
  830.                 bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/xavi/Desenvolupament/Codi/agora-ciudadana/agora_site/agora_core/templatetags/agora_utils.py" in render
  253.                 query=query_dict, data=data, method=method)
File "/home/xavi/Desenvolupament/Codi/agora-ciudadana/agora_site/misc/utils.py" in rest
  405.         res = view.func(hreq, *view.args, **view.kwargs)
File "/home/xavi/Desenvolupament/Codi/agora-ciudadana/agora_site/misc/generic_resource.py" in wrap
  203.                 self.is_authenticated(request)
File "/usr/local/lib/python2.7/dist-packages/tastypie/resources.py" in is_authenticated
  549.         auth_result = self._meta.authentication.is_authenticated(request)
File "/usr/local/lib/python2.7/dist-packages/tastypie/authentication.py" in is_authenticated
  489.             check = backend.is_authenticated(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tastypie/authentication.py" in is_authenticated
  184.             username, api_key = self.extract_credentials(request)
File "/usr/local/lib/python2.7/dist-packages/tastypie/authentication.py" in extract_credentials
  169.             username = request.GET.get('username') or request.POST.get('username')

Exception Type: AttributeError at /xavi/test-agora-1
Exception Value: 'str' object has no attribute 'get'

Could someone have a look ? Thanks!

@edulix
Copy link
Contributor

edulix commented Sep 9, 2014

Hi Xavi: I'm not sure what's the problem, but you shouldn't use sqlite. BTW, I recommend you to try with this deployment script: https://github.com/agoravoting/agora-ciudadana-box

@xaviarias
Copy link
Author

Thanks Edulix. I'll try with the agora box.

@xaviarias
Copy link
Author

After having several problems with the deployment script, I have changed the database to PostgreSQL. The site works much faster than SQL Lite, but the error still appears.

I think is a security issue, regarding at the line authentication.py line 161:

if request.META.get('HTTP_AUTHORIZATION') ...
else:
    username = request.GET.get('username') or request.POST.get('username')
    api_key = request.GET.get('api_key') or request.POST.get('api_key')
    ...

Neither the headers or GET/POST data contain API Key. In debug mode I have set the request.META dictionary to {'HTTP_AUTHORIZATION' : 'apikey xavi:xxxxxxxxxxxxxxxx'} with the proper API Key and it works fine.

The request is generated in agora_view.html line 93:

var ajax_data = {
    'tallied_elections': {% rest request '/agora/' agora.id '/tallied_elections/?limit=3' %},
    'agora': {% rest request '/agora/' agora.id '/' %},
    'user_permissions': {% custom_rest request "POST" '{"action":"get_permissions"}' '/agora/' agora.id '/action/' %}
};

The custom rest request in POST to obtain user permissions must be authenticated in order to succeed.
In any case, the error should not produce this error page. Instead, receiving a 401 Ajax response should only display a blank content.

Searching about the AttributeError 'str' object has no attribute 'get', it seems that the response returned to Django is a string instead of HttpResponse, but debugging the code becomes too complex to find out the exact place.

Could you look ajax_data to see where the headers are managed and maybe add the Authorization header?

@xaviarias
Copy link
Author

Last commit solved the issue, thanks @danigm !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants