Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_authors sometimes returns None values in a list of Author objects. #87

Closed
barrysmyth opened this issue Apr 29, 2024 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@barrysmyth
Copy link

sch.get_authors(['2148555752']) returns a NoneType error because the SS API returns None for this author id and the module does not seem to account for this. A NoneType error is then generated when trying to complete an Author object.


TypeError Traceback (most recent call last)
Cell In [286], line 1
----> 1 sch.get_authors(['2148555752'])

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/semanticscholar/SemanticScholar.py:397, in SemanticScholar.get_authors(self, author_ids, fields)
385 '''Get details for multiple authors at once
386
387 :calls: `POST /author/batch <https://api.semanticscholar.org/api-docs/\
(...)
393 :raises: BadQueryParametersException: if no author was found.
394 '''
396 loop = asyncio.get_event_loop()
--> 397 authors = loop.run_until_complete(
398 self._AsyncSemanticScholar.get_authors(
399 author_ids=author_ids,
400 fields=fields
401 )
402 )
404 return authors

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/nest_asyncio.py:89, in _patch_loop..run_until_complete(self, future)
86 if not f.done():
87 raise RuntimeError(
88 'Event loop stopped before Future completed.')
---> 89 return f.result()

File ~/anaconda3/envs/py39/lib/python3.9/asyncio/futures.py:201, in Future.result(self)
199 self.__log_traceback = False
200 if self._exception is not None:
--> 201 raise self._exception
202 return self._result

File ~/anaconda3/envs/py39/lib/python3.9/asyncio/tasks.py:256, in Task.__step(failed resolving arguments)
252 try:
253 if exc is None:
254 # We use the send method directly, because coroutines
255 # don't have __iter__ and __next__ methods.
--> 256 result = coro.send(None)
257 else:
258 result = coro.throw(exc)

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/semanticscholar/AsyncSemanticScholar.py:543, in AsyncSemanticScholar.get_authors(self, author_ids, fields)
539 payload = { "ids": author_ids }
541 data = await self._requester.get_data_async(
542 url, parameters, self.auth_header, payload)
--> 543 authors = [Author(item) for item in data]
545 return authors

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/semanticscholar/AsyncSemanticScholar.py:543, in (.0)
539 payload = { "ids": author_ids }
541 data = await self._requester.get_data_async(
542 url, parameters, self.auth_header, payload)
--> 543 authors = [Author(item) for item in data]
545 return authors

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/semanticscholar/Author.py:57, in Author.init(self, data)
55 self._papers = None
56 self._url = None
---> 57 self._init_attributes(data)

File ~/anaconda3/envs/py39/lib/python3.9/site-packages/semanticscholar/Author.py:131, in Author._init_attributes(self, data)
129 def _init_attributes(self, data):
130 self._data = data
--> 131 if 'affiliations' in data:
132 self._affiliations = data['affiliations']
133 if 'authorId' in data:

TypeError: argument of type 'NoneType' is not iterable

@danielnsilva danielnsilva added the bug Something isn't working label Apr 29, 2024
@danielnsilva
Copy link
Owner

@barrysmyth,

This issue is similar to #80 regarding the get_papers() method. The solution implemented for that problem has also been applied to the get_authors() method.

This fix will be included in the next release. In the meantime, you can try installing directly from the source.

pip install --no-cache-dir --force-reinstall git+https://github.com/danielnsilva/semanticscholar@master

@j-z10
Copy link

j-z10 commented May 15, 2024

Could you please make a new release to PyPi, since this bug was fixed two weeks ago.
This would be really helpful, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants