Allows user to set their own proxy for the connection session. Sets the proxy if it works. :param http: the http proxy :type http: str :param https: the https proxy (default to the same as http) :type https: str :returns: whether or not the proxy was
(self, http: str, https: str = None)
| 179 | return (False, None) |
| 180 | |
| 181 | def _use_proxy(self, http: str, https: str = None) -> bool: |
| 182 | """Allows user to set their own proxy for the connection session. |
| 183 | Sets the proxy if it works. |
| 184 | |
| 185 | :param http: the http proxy |
| 186 | :type http: str |
| 187 | :param https: the https proxy (default to the same as http) |
| 188 | :type https: str |
| 189 | :returns: whether or not the proxy was set up successfully |
| 190 | :rtype: {bool} |
| 191 | """ |
| 192 | if http[:4] != "http": |
| 193 | http = "http://" + http |
| 194 | if https is None: |
| 195 | https = http |
| 196 | elif https[:5] != "https": |
| 197 | https = "https://" + https |
| 198 | |
| 199 | proxies = {'http://': http, 'https://': https} |
| 200 | if self.proxy_mode == ProxyMode.SCRAPERAPI: |
| 201 | r = requests.get("http://api.scraperapi.com/account", params={'api_key': self._API_KEY}).json() |
| 202 | if "error" in r: |
| 203 | self.logger.warning(r["error"]) |
| 204 | self._proxy_works = False |
| 205 | else: |
| 206 | self._proxy_works = r["requestCount"] < int(r["requestLimit"]) |
| 207 | self.logger.info("Successful ScraperAPI requests %d / %d", |
| 208 | r["requestCount"], r["requestLimit"]) |
| 209 | else: |
| 210 | self._proxy_works = self._check_proxy(proxies) |
| 211 | |
| 212 | if self._proxy_works: |
| 213 | self._proxies = proxies |
| 214 | self._new_session(proxies=proxies) |
| 215 | |
| 216 | return self._proxy_works |
| 217 | |
| 218 | @deprecated(version='1.5', reason="Tor methods are deprecated and are not actively tested.") |
| 219 | def Tor_External(self, tor_sock_port: int, tor_control_port: int, tor_password: str): |
no test coverage detected