mattlisiv / newsapi-python

A Python Client for News API
MIT License
404 stars 140 forks source link

ValueError: Timeout value connect was Timeout(connect=30, read=30, total=None), but it must be an int, float or None. #16

Closed Niranjanb14 closed 6 years ago

Niranjanb14 commented 6 years ago

from newsapi import NewsApiClient

api = NewsApiClient(api_key='XXXXXXXXXXXXXXXXXXXXXXXX')

api.get_top_headlines(sources='bbc-news')

Traceback (most recent call last):

File "", line 1, in api.get_top_headlines(sources='bbc-news')

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\newsapi\newsapi_client.py", line 115, in get_top_headlines r = requests.get(const.TOP_HEADLINES_URL, auth=self.auth, timeout=30, params=payload)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\api.py", line 70, in get return request('get', url, params=params, **kwargs)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\api.py", line 56, in request return session.request(method=method, url=url, **kwargs)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\sessions.py", line 488, in request resp = self.send(prep, **send_kwargs)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\sessions.py", line 609, in send r = adapter.send(request, **kwargs)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\adapters.py", line 423, in send timeout=timeout

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 587, in urlopen timeout_obj = self._get_timeout(timeout)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 302, in _get_timeout return Timeout.from_float(timeout)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\packages\urllib3\util\timeout.py", line 154, in from_float return Timeout(read=timeout, connect=timeout)

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\packages\urllib3\util\timeout.py", line 94, in init self._connect = self._validate_timeout(connect, 'connect')

File "C:\Users\NIRANJAN\Anaconda3\lib\site-packages\requests\packages\urllib3\util\timeout.py", line 127, in _validate_timeout "int, float or None." % (name, value))

ValueError: Timeout value connect was Timeout(connect=30, read=30, total=None), but it must be an int, float or None.

mattlisiv commented 6 years ago

This was due to an issue with the requests library being outdate. The version has been updated on the latest release 0.2.3.

https://github.com/mattlisiv/newsapi-python/commit/c60e84ae2c030491a777baaa43cd062630d0a632#diff-2eeaed663bd0d25b7e608891384b7298R6

You should now be able to pull the latest issue and not receive the error.

Thanks!