newsapi-python icon indicating copy to clipboard operation
newsapi-python copied to clipboard

Not able to get sources for the specific countries

Open omelnik opened this issue 4 years ago • 2 comments

Describe the bug The issue is that I'm able to get sources for countries like: ae, at, be, bg, ch, cn, co, cu, ua, ru.

To Reproduce from newsapi import NewsApiClient

newsapi = NewsApiClient(api_key="api_key") print(newsapi.get_sources(country="ua"))

{'status': 'ok', 'sources': []}

Expected behavior Should be able to get all sources for all countries

omelnik avatar Feb 07 '20 00:02 omelnik

This question on Stack Oveflow shows this same problem happens.

DevGlogicM avatar Aug 19 '20 21:08 DevGlogicM

@omelnik @DevGlogicM I can't get any of the code working from the site. I just signed up for the api but its not giving any country info

from newsapi import NewsApiClient

# Init I swapped in an active API key and the error comes back 
newsapi = NewsApiClient(api_key='xxxxxxxxxxxxxxxxxx')

# /v2/top-headlines
top_headlines = newsapi.get_top_headlines(q='bitcoin',
                                          sources='bbc-news, the-verge',
                                          category='business',
                                          language='en',
                                          country='gb')

# /v2/everything
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)

# /v2/top-headlines/sources
sources = newsapi.get_sources()

So it says ValueError: cannot mix country/category param with sources param. which makes sense as the code was first country='us' so I changed that to country='gb' but no change, so i tried commenting out what I thought might be a us based news outlet and same outcome.

ValueError                                Traceback (most recent call last)
Input In [31], in <cell line: 7>()
      4 newsapi = NewsApiClient(api_key='5af02540ee054b44adb0f6c3af912d62')
      6 # /v2/top-headlines
----> 7 top_headlines = newsapi.get_top_headlines(q='bitcoin',
      8                                           sources='bbc-news',#the-verge',
      9                                           category='business',
     10                                           language='en',
     11                                           country='gb')
     13 # /v2/everything
     14 all_articles = newsapi.get_everything(q='bitcoin',
     15                                       sources='bbc-news',#the-verge',
     16                                       domains='bbc.co.uk,techcrunch.com',
   (...)
     20                                       sort_by='relevancy',
     21                                       page=2)

File ~/sbox/PycharmProjects/Analysis_Finance/lib/python3.8/site-packages/newsapi/newsapi_client.py:105, in NewsApiClient.get_top_headlines(self, q, qintitle, sources, language, country, category, page_size, page)
    103 # Sources
    104 if (sources is not None) and ((country is not None) or (category is not None)):
--> 105     raise ValueError("cannot mix country/category param with sources param.")
    107 # Sources
    108 if sources is not None:

ValueError: cannot mix country/category param with sources param.

datatalking avatar Jun 19 '22 00:06 datatalking