mattlisiv / newsapi-python

A Python Client for News API
MIT License
400 stars 139 forks source link

The base example get_top_headlines() doesn't work. #64

Closed clone95 closed 3 years ago

clone95 commented 4 years ago

raise ValueError("cannot mix country/category param with sources param.")

harryghgim commented 4 years ago

Which language are you using? Did you copy and paste from usage under Client libraries > one of languages and run script? Running newsapi.get_sources() and newsapi.get_top_headlines() at the same time won't work and throw error like below:

  File "/Users/gwanghyeongim/Documents/py/freeCodeCamp/api_craigdennis/.venv/lib/python3.7/site-packages/newsapi/newsapi_client.py", line 105, in get_top_headlines
    raise ValueError("cannot mix country/category param with sources param.")
ValueError: cannot mix country/category param with sources param.
thankblitz commented 3 years ago

Is this fixed? I see the same error too. Any updates on this?

mattlisiv commented 3 years ago

Per the NewsAPI documentation: Note: you can't mix this param with the country or category params. . This library enforces the above rule.

The package is not directly affiliated with the NewsAPI organization, so I would recommend using the example on the README, as I have no ability to update the site's examples.

SYK-08 commented 3 years ago

Python Code

import config from newsapi import NewsApiClient

newsapi = NewsApiClient(api_key=config.api_key)

top_headlines = newsapi.get_top_headlines(q='Neuralink',sources='the-verge',category='technology',language='en',country='us')

When I run this code it shows the Error: ValueError: cannot mix country/category param with sources param How to fix this?