|
5 | 5 | import os |
6 | 6 | from time import sleep |
7 | 7 | from urllib.parse import urlencode |
| 8 | +from warnings import warn |
8 | 9 |
|
9 | 10 | from pubproxpy._singleton import Singleton |
10 | 11 | from pubproxpy.errors import ProxyError, API_ERROR_MAP |
@@ -74,11 +75,19 @@ def __init__(self, *, exclude_used=True, **params): |
74 | 75 | self._shared = _FetcherShared() |
75 | 76 |
|
76 | 77 | def _setup_params(self, params): |
77 | | - """Checks all of the params and renames to acutally work with the API |
78 | | - """ |
| 78 | + """Checks all of the params and renames to acutally work with the API""" |
79 | 79 |
|
80 | 80 | self._verify_params(params) |
81 | 81 |
|
| 82 | + if "api_key" in params and "PUBPROXY_API_KEY" in os.environ: |
| 83 | + warn( |
| 84 | + "The library will be changing the precendence on overriding the API key" |
| 85 | + " when it's present as both a parameter and env var. This involves a" |
| 86 | + " breaking change (hence the warning) More information is available in" |
| 87 | + " this issue" |
| 88 | + " https://github.com/LovecraftianHorror/pubproxpy/issues/11" |
| 89 | + ) |
| 90 | + |
82 | 91 | # Try to read api key from environment if not provided |
83 | 92 | if "api_key" not in params and "PUBPROXY_API_KEY" in os.environ: |
84 | 93 | params["api_key"] = os.environ["PUBPROXY_API_KEY"] |
@@ -174,13 +183,11 @@ def _format_params(self, params): |
174 | 183 | return params |
175 | 184 |
|
176 | 185 | def drain(self): |
177 | | - """Returns any proxies remaining in the current list |
178 | | - """ |
| 186 | + """Returns any proxies remaining in the current list""" |
179 | 187 | return self.get(len(self._proxies)) |
180 | 188 |
|
181 | 189 | def get(self, amount=1): |
182 | | - """Attempts to get `amount` proxies matching the specified params |
183 | | - """ |
| 190 | + """Attempts to get `amount` proxies matching the specified params""" |
184 | 191 | # Remove any blacklisted proxies from the internal list |
185 | 192 | # Note: this needs to be done since reused proxies can sit in the |
186 | 193 | # internal list of separate `ProxyFetcher`s |
@@ -219,6 +226,15 @@ def _fetch(self): |
219 | 226 |
|
220 | 227 | # Query the api |
221 | 228 | resp = requests.get(self._query) |
| 229 | + |
| 230 | + if not resp.ok: |
| 231 | + warn( |
| 232 | + "The library will be changing how API errors are exposed, so that the" |
| 233 | + " different conditions are expressed with different error classes. This" |
| 234 | + " will be a breaking change (hence the warning). More information is" |
| 235 | + " available in this issue" |
| 236 | + " https://github.com/LovecraftianHorror/pubproxpy/issues/11" |
| 237 | + ) |
222 | 238 | # And ensure the response is ok |
223 | 239 | resp.raise_for_status() |
224 | 240 |
|
|
0 commit comments