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

newsapi.newsapi_exception.NewsAPIException #59

Open
reshu-b7 opened this issue Oct 20, 2019 · 1 comment
Open

newsapi.newsapi_exception.NewsAPIException #59

reshu-b7 opened this issue Oct 20, 2019 · 1 comment

Comments

@reshu-b7
Copy link

While trying to run the following code snippet , which is actually a part of documentation :

all_articles = newsapi.get_everything(q='bitcoin',
                                      sources='bbc-news,the-verge',
                                      domains='bbc.co.uk,techcrunch.com',
                                      from_param='2017-12-01',
                                      to='2017-12-12',
                                      language='en',
                                      sort_by='relevancy',
                                      page=2)

I am getting this error again and again :

Traceback (most recent call last):
  File "news.py", line 16, in <module>
    page=2)
  File "C:\Python27\lib\site-packages\newsapi\newsapi_client.py", line 261, in get_everything
    raise NewsAPIException(r.json())
newsapi.newsapi_exception.NewsAPIException

Any suggestions on why this might be happening ?

@danielmichaels
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants