Open devvmh opened 8 years ago
Faced exactly the same problem with Russian unicode characters. I was carefully check out the source of cubes/compat.py and cubes/cells.py, and notice, that it has completely different code for python 2.7 and 3.0+. I've also has python 2.7, so I decided to try with python 3.4 and it helps. Just creating virtualenv with python 3.4, installing cubes 1.1 in it with all prerequesites and adding 'source env/bin/activate' before starting cube server completely resolve my problem.
Thanks @fezeev! I'll give that a try next week!
Can you please try now with the master?
I can confirm the same bug exists, with a different error message, using the latest master
File "/Users/devin/olap-cubes/venv/lib/python2.7/site-packages/cubes/sql/browser.py", line 402, in provide_aggregate
for_summary=True)
File "/Users/devin/olap-cubes/venv/lib/python2.7/site-packages/cubes/sql/browser.py", line 542, in aggregation_statement
(",".join([compat.to_unicode(cut) for cut in cell.cuts]),
File "/Users/devin/olap-cubes/venv/lib/python2.7/site-packages/cubes/compat.py", line 58, in to_unicode
s = str(s)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 23-25: ordinal not in range(128)
127.0.0.1 - - [06/Jun/2016 10:25:56] "GET /cube/plans/aggregate?drilldown=utm_source%40default%3Autm_source&cut=utm_source%40default%3Aseo%3B%E4%B8%8D%E7%9F%A5%E9%81%93%3B%E5%90%88%E4%BD%9C%E7%B1%BB%7Cimported_at%40ymd%3A2014%2C6%2C6- HTTP/1.1" 500 -
Relevant requirements.txt line is
git+https://github.com/DataBrewery/cubes.git@e0181b977d1ffbc6bd81335f0b6355f26b860f13
I am still using Python 2.7.10.
Thanks for working on this!
EDIT: I've done a bit more digging. Commenting out line 58 of compat.py (s = str(s)
) gives me an interesting error:
File "/Users/devin/olap-cubes/venv/lib/python2.7/site-packages/cubes/sql/browser.py", line 542, in aggregation_statement
(",".join([compat.to_unicode(cut) for cut in cell.cuts]),
File "/Users/devin/olap-cubes/venv/lib/python2.7/site-packages/cubes/compat.py", line 61, in to_unicode
return unicode(s, enc)
TypeError: coercing to Unicode: need string or buffer, SetCut found
It appears as if cell.cuts is sometimes returning strings, and sometimes returning SetCut objects. My guess would be that the unicode characters in the URL are returned as SetCut objects, since they are the options that cause the problem
I was having a similar problem with u'\xe3' character.
I've changed the line 58 of compat.py froms = str(s)
to s = str(s.__str__().encode('utf-8','ignore'))
and the same for line 52 of formatters.py and works fine for me.
Thanks @fezeev.
Summary
Unicode errors! I'm including an error traceback, a git patch that solves the error, and then a subsequent traceback for a second error I couldn't solve. I appreciate any help getting this working!
Details
I'm using cubesviewer to build a number of views of data from a rails application. A lot of the dimensions include Chinese characters.
In particular, I have a cube called "plans" that can be filtered on utm_source (among other dimensions). When I try to (using cubesviewer) select only plans with specific utm_source values that include chinese characters, I get an error.
I'm using cubes 1.1, but I believe the problem persists in stable versions anyways. Here's the relevant line from requirements.txt:
git+https://github.com/DataBrewery/cubes.git@6d83f04acb34eeb0b904dd1af0e97eda6621bf6c
I'm filtering on the "imported_at" date property of the cube, and drilling down on the "utm_source" (to build a cubesviewer pie chart). The relevant filter is looking for utm_source values equal to one of "seo", "不知道", or "合作类". I've used these values since they're short; the bug also appears for any combination that includes unicode characters. Here is the traceback of the error from the slicer server logs.
And the urldecoded url is
Though I don't think this is the correct solution, I am able to resolve this particular bug (and a related one) by applying these changes to
cubes/sql/browser.py
:However, this simply led me to another bug I couldn't fix. Here's the second slicer server traceback: