Custom dimensions and metrics generating Server Error

99 views
Skip to first unread message

Gerard Baquer

unread,
Jul 17, 2014, 5:17:13 AM7/17/14
to google-analyti...@googlegroups.com
Hi guys,

I'm using SuperProxy to power some custom dashboards.After enabling the endpoints I query them in my application in the following way. Where endpointURL corresponds to the endpoint URL followed by "&format=data-table-response".

var query = new google.visualization.Query(endpointURL);
query.setRefreshInterval(600);
query.send(function (response) {
   todayDataTable = response.getDataTable();   
   doSomething();

It all works fine with most of my queries but when they include custom dimensions or metrics (ga:dimension3, ga:metric2 ...) the query returns the following error message:

Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.

This happens with both the Core API and the Real Time API and only happens when querying the data in the DataTable (JSON Response)  and DataTable (JSON String). The JSON format works just fine.

Does anybody know any workarounds to this?

The easiest one I can think of is to query the endpoint in the JSON format and use that JSON object to build the DataTable. It sounds really simple and easy but I haven't had much luck implementing it.

Thanks,
Gerard Baquer

Gerard Baquer

unread,
Jul 17, 2014, 6:38:38 AM7/17/14
to google-analyti...@googlegroups.com
Here's a bit more of information on the error I'm getting:

'ascii' codec can't encode character u'\xf9' in position 73: ordinal not in range(128)
Any suggestions on how to solve it or what could be the reason? Here you have the complete description of the error:

  1. 2014-07-17 02:56:24.703 /query?id=[queryId]&format=data-table-response500 65ms 0kb Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 module=default version=1
    87.236.135.147 -  [17/Jul/2014:02:56:24 -0700] "GET /query?id=[queryId]&format=data-table-response HTTP/1.1" 500 119 - "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36" "elleitalylivedashboard.appspot.com" ms=66 cpu_ms=0 cpm_usd=0.000013 app_engine_release=1.9.7 trace_id=[traceId] instance=[instance]
  2. E2014-07-17 02:56:24.698
    'ascii' codec can't encode character u'\xf9' in position 73: ordinal not in range(128)
    Traceback (most recent call last):
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
        rv = self.handle_exception(request, response, e)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
        rv = self.router.dispatch(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
        return route.handler_adapter(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
        return handler.dispatch()
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
        return self.handle_exception(e, self.app.debug)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
        return method(*args, **kwargs)
      File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/public.py", line 63, in get
        query_id, response_format, transform)
      File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/util/query_helper.py", line 395, in GetPublicEndpointResponse
    transformed_response_content = transform.Transform(response_content) File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/transform/transformers.py", line 287, in Transform
    data_table_rows = GetDataTableRows(content) File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/transform/transformers.py", line 512, in GetDataTableRows
    data_row_value = convert_to(data) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf9' in position 73: ordinal not in range(128)
  3. E2014-07-17 02:56:24.698
    Traceback (most recent call last):
      File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 266, in Handle
        result = handler(dict(self._environ), self._StartResponse)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
        response = self._internal_error(e)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
        rv = self.handle_exception(request, response, e)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
        rv = self.router.dispatch(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
        return route.handler_adapter(request, response)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
        return handler.dispatch()
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
        return self.handle_exception(e, self.app.debug)
      File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
        return method(*args, **kwargs)
      File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/public.py", line 63, in get
    query_id, response_format, transform) File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/util/query_helper.py", line 395, in GetPublicEndpointResponse
    transformed_response_content = transform.Transform(response_content) File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/transform/transformers.py", line 287, in Transform
    data_table_rows = GetDataTableRows(content) File "/base/data/home/apps/s~[domainId]/1.377270589851423696/controllers/transform/transformers.py", line 512, in GetDataTableRows
    data_row_value = convert_to(data) UnicodeEncodeError: 'ascii' codec can't encode character u'\xf9' in position 73: ordinal not in range(128)

Thanks,
Gerard Baquer

bakablah

unread,
Jul 17, 2014, 7:12:55 AM7/17/14
to Gerard Baquer, google-analyti...@googlegroups.com
Hey Gerard,

I've seen this error before in my own Super proxy project. I've got a fix that would strip out these ascii characters so that the feed will not crash.

- Navigate into your Super Proxy source code.
- Navigate to src\controllers\transform\transformers.py
- Edit the file.
- Go to line 512, it'll read: data_row_value = convert_to(data)
- change that to: data_row_value = convert_to(data.encode('ascii','ignore'))
- Save and redeploy to Google App Engine.

If you have done it right, the block of code should now read:


        if convert_to:
          data_row_value = convert_to(data.encode('ascii','ignore'))
        else:
          data_row_value = data.encode('UTF-8')
        data_row.update({
            column_headers[index].get('name', UNKNOWN_LABEL): data_row_value
        })


This fix will ignore all these pesky ASCII characters and will return the results normally.

Regards,
Wilfrid


--
You received this message because you are subscribed to the Google Groups "Google Analytics superProxy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-analytics-sup...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gerard Baquer

unread,
Jul 17, 2014, 7:58:45 AM7/17/14
to bakablah, google-analyti...@googlegroups.com
Thanks Wilfrid this made the trick.
--
This is a test signature

Karl Equi

unread,
Oct 23, 2014, 12:32:53 PM10/23/14
to google-analyti...@googlegroups.com, baquer...@gmail.com
This is beautiful Wilfrid.  Just the ticket. 

Many thanks for posting. 
Reply all
Reply to author
Forward
0 new messages