ourresearch / total-impact-core

An api and backend code to gather the impacts of diverse scholarly products online.
http://impactstory.org
Other
55 stars 7 forks source link

unicode bug in ORCID member_items #123

Closed hpiwowar closed 11 years ago

hpiwowar commented 11 years ago
Jun 18 05:42:52 ti-core app/web.1:  [51]    ERROR                     MainThread totalimpact - Exception on /provider/orcid/memberitems/0000-0001-8907-4150‎ [GET] 
Jun 18 05:42:52 ti-core app/web.1:  Traceback (most recent call last): 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1292, in wsgi_app 
Jun 18 05:42:52 ti-core app/web.1:      response = self.full_dispatch_request() 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1062, in full_dispatch_request 
Jun 18 05:42:52 ti-core app/web.1:      rv = self.handle_user_exception(e) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1060, in full_dispatch_request 
Jun 18 05:42:52 ti-core app/web.1:      rv = self.dispatch_request() 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/flask/app.py", line 1047, in dispatch_request 
Jun 18 05:42:52 ti-core app/web.1:      return self.view_functions[rule.endpoint](**req.view_args) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.9.0.21/newrelic/api/object_wrapper.py", line 220, in __call__ 
Jun 18 05:42:52 ti-core app/web.1:      self._nr_instance, args, kwargs) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.9.0.21/newrelic/api/function_trace.py", line 81, in literal_wrapper 
Jun 18 05:42:52 ti-core app/web.1:      return wrapped(*args, **kwargs) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.9.0.21/newrelic/api/object_wrapper.py", line 220, in __call__ 
Jun 18 05:42:52 ti-core app/web.1:      self._nr_instance, args, kwargs) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/.heroku/python/lib/python2.7/site-packages/newrelic-1.9.0.21/newrelic/api/transaction_name.py", line 51, in literal_wrapper 
Jun 18 05:42:52 ti-core app/web.1:      return wrapped(*args, **kwargs) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/totalimpact/views.py", line 266, in provider_memberitems_get 
Jun 18 05:42:52 ti-core app/web.1:      ret = provider.member_items(query) 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/totalimpact/providers/orcid.py", line 90, in member_items 
Jun 18 05:42:52 ti-core app/web.1:      url = self._get_templated_url(provider_url_template, query_string, "members") 
Jun 18 05:42:52 ti-core app/web.1:    File "/app/totalimpact/providers/provider.py", line 148, in _get_templated_url 
Jun 18 05:42:52 ti-core app/web.1:      provider=self.provider_name, id=id)) 
Jun 18 05:42:52 ti-core app/web.1:  UnicodeEncodeError: 'ascii' codec can't encode character u'\u200e' in position 19: ordinal not in range(128) ```
hpiwowar commented 11 years ago

This was due to a nonprinting character being included in the ORCID:

u'0000-0001-8907-4150\u200e'

Maybe solution something like

def filter_non_printable(str):
      return ''.join(c for c in str if unicodedata.category(c)[0] not in ["C", "M", "Z"])
hpiwowar commented 11 years ago

fixed in commit c10b6bb7aec9cba3f62ece1a5b47d0fe44aaf7ca