|
2 | 2 | from newsapi.newsapi_auth import NewsApiAuth |
3 | 3 | from newsapi import const |
4 | 4 | from newsapi.newsapi_exception import NewsAPIException |
| 5 | +from sys import version_info |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class NewsApiClient(object): |
@@ -45,10 +46,17 @@ def get_top_headlines(self, q=None, sources=None, language='en', country=None, c |
45 | 46 |
|
46 | 47 | # Keyword/Phrase |
47 | 48 | if q is not None: |
48 | | - if type(q) == str: |
| 49 | + if version_info[0] == 3: |
| 50 | + q_is_str = isinstance(q, str) |
| 51 | + elif version_info[0] == 2: |
| 52 | + q_is_str = isinstance(q, basestring) |
| 53 | + else: |
| 54 | + raise SystemError("unsupported version of python detected (supported versions: 2, 3)") |
| 55 | + |
| 56 | + if q_is_str: |
49 | 57 | payload['q'] = q |
50 | 58 | else: |
51 | | - raise TypeError('keyword/phrase q param should be a of type str') |
| 59 | + raise TypeError('keyword/phrase q param should be of type str') |
52 | 60 |
|
53 | 61 | # Sources |
54 | 62 | if (sources is not None) and ((country is not None) or (category is not None)): |
@@ -160,7 +168,14 @@ def get_everything(self, q=None, sources=None, domains=None, exclude_domains=Non |
160 | 168 |
|
161 | 169 | # Keyword/Phrase |
162 | 170 | if q is not None: |
163 | | - if type(q) == str: |
| 171 | + if version_info[0] == 3: |
| 172 | + q_is_str = isinstance(q, str) |
| 173 | + elif version_info[0] == 2: |
| 174 | + q_is_str = isinstance(q, basestring) |
| 175 | + else: |
| 176 | + raise SystemError("unsupported version of python detected (supported versions: 2, 3)") |
| 177 | + |
| 178 | + if q_is_str: |
164 | 179 | payload['q'] = q |
165 | 180 | else: |
166 | 181 | raise TypeError('keyword/phrase q param should be of type str') |
|
0 commit comments