Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard not being show due to CORS problems #85

Closed
acorbi opened this issue Dec 22, 2017 · 2 comments
Closed

Dashboard not being show due to CORS problems #85

acorbi opened this issue Dec 22, 2017 · 2 comments

Comments

@acorbi
Copy link

acorbi commented Dec 22, 2017

Steps to reproduce

  1. Head to https://pp.opendevelopmentmyanmar.net/dashboards/myanmar-data/

Expected behaviour

The dashboard and data visualizations should show up

Observed behaviour

They do not show up and following error is to be found on the Browser's javascript console

image

Looking at CKAN's log, following error could be identified:

Traceback (most recent call last):
  File "./ckan/config/middleware/__init__.py", line 136, in __call__
    return self.apps[app_name](environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/paste/cascade.py", line 130, in __call__
    return self.apps[-1](environ, start_response)
  File "./ckan/config/middleware/common_middleware.py", line 61, in __call__
    return self.app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/paste/registry.py", line 379, in __call__
    app_iter = self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/repoze/who/middleware.py", line 117, in __call__
    wrapper.finish_response(remember_headers)
  File "/usr/local/lib/python2.7/dist-packages/repoze/who/middleware.py", line 181, in finish_response
    write = self.start_response(self.status, headers, self.exc_info)
TypeError: http header key must be a string

By outputting the headers on the log, following list of headers was observed:

Alex Corbi, [22.12.17 16:24]
[('Pragma', 'no-cache'), ('Cache-Control', 'no-cache'), ('Content-Type', 'application/json;charset=utf-8'), ('Content-Length', '29517'), (u'Access-Control-Allow-Origin', u'*'), (u'Access-Control-Allow-Methods', u'POST, PUT, GET, DELETE, OPTIONS'), (u'Access-Control-Allow-Headers', u'X-CKAN-API-KEY, Authorization, Content-Type')]

With these 2 pieces of information, the solution seems to convert those unicode strings to normal strings (without u'')

In order to test this, I have set the headers manually on File "/usr/local/lib/python2.7/dist-packages/repoze/who/middleware.py", line 181, in finish_response, like this:

test_headers = [('Pragma', 'no-cache'), ('Cache-Control', 'no-cache'), ('Content-Type', 'application/json;charset=utf-8'), ('Content-Length', '29517'), ('Access-Control-Allow-Origin', '*'), ('Access-Control-Allow-Methods', 'POST, PUT, GET, DELETE, OPTIONS'), ('Access-Control-Allow-Headers', 'X-CKAN-API-KEY, Authorization, Content-Type')]
write = self.start_response(self.status, test_headers, self.exc_info)

which fixes the issue. However this is not a clean solution since it would affect other requests...

@acorbi
Copy link
Author

acorbi commented Dec 27, 2017

@DragonVirus can you please help identifying a potential fix for this issue.

@acorbi
Copy link
Author

acorbi commented Dec 28, 2017

@DragonVirus I think a potential solution would be to use jsonp https://learn.jquery.com/ajax/working-with-jsonp/

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

No branches or pull requests

1 participant