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

Not able to get sources for the specific countries #62

Open
omelnik opened this issue Feb 7, 2020 · 2 comments
Open

Not able to get sources for the specific countries #62

omelnik opened this issue Feb 7, 2020 · 2 comments

Comments

@omelnik
Copy link

omelnik commented Feb 7, 2020

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

@DevGlogicM
Copy link

This question on Stack Oveflow shows this same problem happens.

@datatalking
Copy link

datatalking commented Jun 19, 2022

@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.

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

3 participants