mattlisiv / newsapi-python

A Python Client for News API
MIT License
376 stars 130 forks source link

Wrong example for python #32

Closed mabodx closed 5 years ago

mabodx commented 5 years ago

I follow this document https://newsapi.org/docs/client-libraries/python and test python api.

Seems like the follow code will get error I paste. sources = newsapi.get_sources()

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "crawler.py", line 93, in <module>
    crawler.crawl()
  File "crawler.py", line 84, in crawl
    sources = newsapi.get_sources()
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/newsapi/newsapi_client.py", line 311,
 in get_sources
    r = requests.get(const.SOURCES_URL, auth=self.auth, timeout=30, params=payload)
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/requests/api.py", line 72, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/requests/sessions.py", line 513, in r
equest
    resp = self.send(prep, **send_kwargs)
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/requests/sessions.py", line 623, in s
end
    r = adapter.send(request, **kwargs)
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/requests/adapters.py", line 514, in s
end
    raise SSLError(e, request=request)
requests.exceptions.SSLError: ("bad handshake: SysCallError(-1, 'Unexpected EOF')",)
mabodx commented 5 years ago

And this code

top_headlines = newsapi.get_top_headlines(q='bitcoin',
                                          sources='bbc-news,the-verge',
                                          category='business',
                                          language='en',
                                          country='us')

I also get error like this

Traceback (most recent call last):
  File "crawler.py", line 90, in <module>
    crawler.crawl()
  File "crawler.py", line 69, in crawl
    country='us')
  File "/Users/mabodx/anaconda/lib/python3.6/site-packages/newsapi/newsapi_client.py", line 55, in get_top_headlines
    raise ValueError('cannot mix country/category param with sources param.')
ValueError: cannot mix country/category param with sources param.
mabodx commented 5 years ago

does python has pageSize params? https://newsapi.org/docs/endpoints/top-headlines

mattlisiv commented 5 years ago

Hi,

The top headlines error is due to the mix of country and category parameters. These cannot both be arguments.

Also, for paging, please use the argument page_size.