Open reshu-b7 opened 5 years ago
I've tried to replicate this in Python 2.7.17 and 3.7.4 with the following results.
python3:
I started with Python 3 because I am more familiar with it. The snippet you've supplied works as expected with a caveat; are you using a free plan? If so, you will get the following exception:
Traceback (most recent call last):
File "/home/daniel/Code/junkyard/newsapi_test.py", line 12, in <module>
page=2)
File "/home/daniel/.virtualenvs/scripts/lib/python3.7/site-packages/newsapi/newsapi_client.py", line 261, in get_everything
raise NewsAPIException(r.json())
newsapi.newsapi_exception.NewsAPIException: {'status': 'error', 'code': 'parameterInvalid', 'message': 'You are trying to request results too far in the past. Your plan permits you to request articles as far back as 2019-09-26, but you have requested 2018-10-01. To extend this please upgrade to a paid plan.'}
Adjusting the from_param
and to
within the allowable date range returns as expected.
python2:
Running the same all_articles
command returns the exception as detailed by @reshu-b7
Traceback (most recent call last):
File "/home/daniel/Code/junkyard/newsapi_test.py", line 12, in <module>
page=2)
File "/home/daniel/.virtualenvs/py2/lib/python2.7/site-packages/newsapi/newsapi_client.py", line 261, in get_everything
raise NewsAPIException(r.json())
newsapi.newsapi_exception.NewsAPIException
Again, adjusting the from_param
and to
parameters works as excepted.
For clarity, the snippet I used to get it working:
all_articles = newsapi.get_everything(q='bitcoin',
sources='bbc-news,the-verge',
domains='bbc.co.uk,techcrunch.com',
from_param='2019-10-01',
to='2019-10-12',
language='en',
sort_by='relevancy',
page=2)
Without doing much more investigation than that, I would suggest it is a case of the exception not raising as expected in Python 2 and leaving the user guessing as to the problem.
Hope that helps, or gets us looking at it.
While trying to run the following code snippet , which is actually a part of documentation :
I am getting this error again and again :
Any suggestions on why this might be happening ?