TypeError: expected string or buffer
Vaits opened this issue · 25 comments
Hello,
using wos
I stumbled upon following TypeError:
>>> with WosClient(username, password, lite=True) as client:
print wos.utils.query(client, 'AU=Knuth Donald')
Authenticated (SID: ...)
Traceback (most recent call last):
File "<ipython-input-7-51b5a119f6af>", line 19, in <module>
print wos.utils.query(client, 'AU=Knuth Donald')
File "/home/.../anaconda3/envs/py27/lib/python2.7/site-packages/wos/utils.py", line 22, in query
for x in range(offset, count+1, limit)]
File "/home/.../anaconda3/envs/py27/lib/python2.7/site-packages/wos/utils.py", line 12, in single
xml = _re.sub(' xmlns="[^"]+"', '', result.records, count=1).encode('utf-8')
File "/home/.../anaconda3/envs/py27/lib/python2.7/re.py", line 155, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or buffer
I used different queries, but I always get the same error. I'm using the latest wos
version 0.1.9 and updated regex recently. Do you have some advice for me?
Hi @Vaits , for some reason the lite version is producing an output that has a different format from the one used in the pro version. I couldn't try it for a long time but now I received an API also for the lite version, so I'll try to fix it.
I'll open another branch for the modification required for the lite version and I'll let you know when they are testable, so that you can test it and give me some feedback and when everything works as expected I'll merge the changes in the master branch.
Hey enricobacis, thanks for your fast reply and the work you put into this! I'm looking forward to the update.
I just stumbled across this branch when looking at an issue we were having. As far as I can tell, the new branch works, thanks!
At the moment, I only seem to be able to fetch the first element. If I do something like
from wos import WosClient
import wos.utils
with WosClient('JohnDoe', '12345') as client:
print(wos.utils.query(client, 'AU=Tao Terrence'))
There are 137 records elements within the <return>
element, but I only get the first one. I've made a barebones pull request which describes the issue a bit, but I'm not really sure what the best fix would be.
Thanks for the fast update @enricobacis. I'm on vacation right now, so I am sorry for the delay. I'll test the changes tomorrow.
@Vido , any news on this side?
I downloaded the client.py
file from the wos-lite
branch and than hacked it a little bit, in order to get what I wanted.
Thanks.
@Vido Feel free to send a pull request if you want
Hi, I've tried this fix, and I am still receiving this error.
I'm a bit new to Python, so I apologize if it's an operator error.
Thank you!
Are you sure you have downloaded the code in the wos-lite
branch? Could you please post here the error message you receive?
Traceback (most recent call last): File "/Users/mattchu/Downloads/wos-master/wos/testquery.py", line 9, in <module> print wos.utils.query(wosclient=client, wos_query='AU=Knuth Donald') File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wos/utils.py", line 22, in query for x in range(offset, count+1, limit)] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wos/utils.py", line 12, in single xml = _re.sub(' xmlns="[^"]+"', '', result.records, count=1).encode('utf-8') File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 155, in sub return _compile(pattern, flags).sub(repl, string, count) TypeError: expected string or buffer
I did download the wos-lite branch. I will continue troubleshooting. Thanks for the reply!
from wos import WosClient`
import wos.utils`
user = <user>
pw = <pw>
with WosClient(user, pw, lite=True) as client:
client.connect()
print wos.utils.query(wosclient=client, wos_query='AU=Knuth Donald')
It's a very simple test for the query; I think I actually just took it off the sample.
Actually you don't need the line:
client.connect()
it's already done by the with
statement. By the way I tried your exact code on the wos-lite
branch and it works.. I don't really know what to suggest at this point. Have you also installed the code with pip or have you just downloaded the wos-lite branch? Because your code may be using the other version of the library without you knowing
Yup. Dumb mistake. Used the pip install
a while ago and forgot I was using the other version. Tried it on the wos-lite
branch and it works.
What is the status of the wos-lite branch? Can it be merged?
It needs testers, are you using it?
I installed this branch now and tested it. The first tests work fine:
1.) Connect with our credentials to WoS Lite Webservices works fine:
$ wos --user <***user-name***> --password <***password***> --lite connect
Authenticated (SID: <***sid***>)
- ) The search for
Knuth Donald
doesn't find any results, but this is the same in the webinterface. Possibly different for us, because we only license the Social Science Citation Index.
$ wos --lite --sid <***sid***> query 'AU=Knuth Donald' -c1
<?xml version="1.0" ?>
<return>
<queryId>18</queryId>
<recordsFound>0</recordsFound>
<recordsSearched>8337838</recordsSearched>
</return>
3.) Relaxed search for Knuth D
finds 31 results as in our online version and shows the first one here:
$ wos --lite --sid <***sid***> query 'AU=Knuth D' -c1
<?xml version="1.0" ?>
<return>
<queryId>19</queryId>
<recordsFound>31</recordsFound>
<recordsSearched>8337838</recordsSearched>
<records>
<uid>WOS:A1979GQ83700003</uid>
<title>
<label>Title</label>
<value>MATHEMATICAL TYPOGRAPHY</value>
</title>
<doctype>
<label>Doctype</label>
<value>Article</value>
</doctype>
<source>
<label>Issue</label>
<value>2</value>
</source>
<source>
<label>Pages</label>
<value>337-372</value>
</source>
<source>
<label>Published.BiblioYear</label>
<value>1979</value>
</source>
<source>
<label>SourceTitle</label>
<value>BULLETIN OF THE AMERICAN MATHEMATICAL SOCIETY</value>
</source>
<source>
<label>Volume</label>
<value>1</value>
</source>
<authors>
<label>Authors</label>
<value>KNUTH, DE</value>
</authors>
<other>
<label>Identifier.Ids</label>
<value>GQ837</value>
</other>
<other>
<label>Identifier.Issn</label>
<value>0273-0979</value>
</other>
<other>
<label>Identifier.Xref_Doi</label>
<value>10.1090/S0273-0979-1979-14598-1</value>
</other>
<other>
<label>ResearcherID.Disclaimer</label>
<value>ResearcherID data provided by Clarivate Analytics</value>
</other>
</records>
</return>
- The DOI lookup gives the message "Not implemented for WOS Lite":
$ wos --lite --sid <***sid***> doi '10.1007/s00283-010-9170-7'
ERROR: Not implemented for WOS Lite
Anything else I should test? Also @mrchu39 confirmed that the branch works.
Ok, this has been open for too long. I'll consider the wos-lite
branch as final and I'll merge it to master.
I'll bump the version to 0.2
, thus if you have any problem because of the merge, please revert to 0.1.x and open an issue.