enricobacis/wos

AttributeError: 'str' object has no attribute 'decode'

Closed this issue · 1 comments

Prerequisites

Make sure these boxes are checked before filling an issue

  • This issue is not the No matches returned for Username or IP
    connection problem detailed here
  • I can reproduce the problem
  • I am running the latest version

Version

Name: wos
Version: 0.2.4
Summary: Web of Science client using API v3.
Home-page: http://github.com/enricobacis/wos
Author: Enrico Bacis
Author-email: enrico.bacis@gmail.com
License: MIT
Location: /home/pietro/.local/lib/python3.7/site-packages
Requires: limit, suds-py3
Required-by:

Description

The following error is raise by any attempt to use wos.utils.query(wc, '...'):

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-f18b21272e9c> in <module>
----> 1 risultato = wos.utils.query(wc, 'DO=10.1287/mnsc.2016.2601')

~/.local/lib/python3.7/site-packages/wos/utils.py in query(wosclient, wos_query, xml_query, count, offset, limit)
     33     """Query Web of Science and XML query results with multiple requests."""
     34     results = [single(wosclient, wos_query, xml_query, min(limit, count-x+1), x)
---> 35                for x in range(offset, count+1, limit)]
     36     if xml_query:
     37         return [el for res in results for el in res]

~/.local/lib/python3.7/site-packages/wos/utils.py in <listcomp>(.0)
     33     """Query Web of Science and XML query results with multiple requests."""
     34     results = [single(wosclient, wos_query, xml_query, min(limit, count-x+1), x)
---> 35                for x in range(offset, count+1, limit)]
     36     if xml_query:
     37         return [el for res in results for el in res]

~/.local/lib/python3.7/site-packages/wos/utils.py in single(wosclient, wos_query, xml_query, count, offset)
     23 def single(wosclient, wos_query, xml_query=None, count=5, offset=1):
     24     """Perform a single Web of Science query and then XML query the results."""
---> 25     records = _get_records(wosclient, wos_query, count, offset)
     26     xml = _re.sub(' xmlns="[^"]+"', '', records, count=1).encode('utf-8')
     27     if not xml_query: return prettify(xml)

~/.local/lib/python3.7/site-packages/wos/utils.py in _get_records(wosclient, wos_query, count, offset)
     15         return _re.search(pattern, result, _re.S).group(0)
     16     else:
---> 17         return wosclient.search(wos_query, count, offset).records
     18 
     19 def prettify(xml):

~/.local/lib/python3.7/site-packages/wos/client.py in _fn(self, *args, **kwargs)
     69             if not self._SID:
     70                 raise RuntimeError('Session closed. Invoke connect() before.')
---> 71             resp = fn(self, *args, **kwargs)
     72             return (self._search.last_received().str() if self.is_lite()
     73                     else resp)

~/.local/lib/python3.7/site-packages/wos/client.py in search(self, query, count, offset, editions, symbolicTimeSpan, timeSpan, retrieveParameters)
    183             queryParameters=_OrderedDict([
    184                 ('databaseId', 'WOS'),
--> 185                 ('userQuery', query.decode('UTF-8')),
    186                 ('editions', editions),
    187                 ('symbolicTimeSpan', symbolicTimeSpan),

AttributeError: 'str' object has no attribute 'decode'

Everything works fine if I revert 6583d26 (remove the decode).

Was #33 a bug with Python 2? It definitely broke my Python 3 usage, so if this is the case, it should be sufficient to check the Python version (happy to propose a PR).

Yep, right. Compatibility between python2 and python3 unicode string is hard :D

It should be fixed in 0.2.5 which is rolling out now.