I am using StackAPI to extract the python related question, answers, and comments. I use following code to extract the questions related to Python.
from stackapi import StackAPI
SITE = StackAPI('stackoverflow')
questions = SITE.fetch('questions', tagged='python', fromdate=from_date, todate=today,filter='withbody')
Then I extract the question_id
list from the retrieved questions to get the answers related to retrieve question
quest_ids= []
for quest in questions['items']:
quest_ids.insert(len(quest_ids),quest['question_id'])
All question related ids are in quest_ids
. Now I use quest_ids
list to retrieve the answers of those question by following code:
answers =SITE.fetch('questions/{ids}/answers',ids=quest_ids,filter='withbody')
However, when I run the above code, I get the following errors:
JSONDecodeError Traceback (most recent call last) ~/anaconda3/lib/python3.6/site-packages/stackapi/stackapi.py in
fetch(self, endpoint, page, key, filter, **kwargs)
189 response.encoding = 'utf-8-sig'
--> 190 response = response.json()
191 except ValueError as e:
~/anaconda3/lib/python3.6/site-packages/requests/models.py in
json(self, **kwargs)
896 pass
--> 897 return complexjson.loads(self.text, **kwargs)
898
~/anaconda3/lib/python3.6/json/__init__.py in loads(s, encoding, cls,
object_hook, parse_float, parse_int, parse_constant,
object_pairs_hook, **kw)
353 parse_constant is None and object_pairs_hook is None and not kw):
--> 354 return _default_decoder.decode(s)
355 if cls is None:
~/anaconda3/lib/python3.6/json/decoder.py in decode(self, s, _w)
338 """
--> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
340 end = _w(s, end).end()
~/anaconda3/lib/python3.6/json/decoder.py in raw_decode(self, s, idx)
356 except StopIteration as err:
--> 357 raise JSONDecodeError("Expecting value", s, err.value) from None
358 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
StackAPIError Traceback (most recent call
last) <ipython-input-43-8d66d5fd3e65> in <module>()
----> 1 answers =SITE.fetch('questions/{ids}/answers',ids=temp,filter='withbody')
~/anaconda3/lib/python3.6/site-packages/stackapi/stackapi.py in
fetch(self, endpoint, page, key, filter, **kwargs)
190 response = response.json()
191 except ValueError as e:
--> 192 raise StackAPIError(self._previous_call, str(e), str(e), str(e))
193
194 try: