-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
640a56c
commit 1fe7c67
Showing
4 changed files
with
9 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "requests-anon" | ||
version = "0.1.0" | ||
version = "0.1.1" | ||
description = "Execute HTTPS requests to a server using anonymous proxies." | ||
authors = ["Nicolò Boschi <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
import logging | ||
|
||
import requests | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def request_with_anon_proxy_unsafe(method: str, url: str, **kwargs): | ||
def anon_request(method, url, **kwargs): | ||
return _request_with_proxy(False, method, url, **kwargs) | ||
|
||
|
||
def request_with_anon_proxy(method, url, **kwargs): | ||
return _request_with_proxy(True, method, url, **kwargs) | ||
|
||
|
||
def _request_with_proxy(safe, method, url, **kwargs): | ||
response = requests.get("https://advanced.name/freeproxy/66d817afbff12?type=socks5") | ||
response.raise_for_status() | ||
proxies = response.text.splitlines() | ||
for proxy in proxies: | ||
logging.debug(f"Testing proxy {proxy}") | ||
logger.debug(f"Testing proxy {proxy}") | ||
try: | ||
args = {**kwargs, "proxies": {"https": "socks5://" + proxy}} | ||
if not safe: | ||
args["verify"] = False | ||
response = requests.request(method, url, **args) | ||
except Exception as e: | ||
logging.debug(f"Proxy {proxy} failed: {e}") | ||
logger.debug(f"Proxy {proxy} failed: {e}") | ||
continue | ||
if response.status_code < 400: | ||
logging.debug(f"Proxy {proxy} success") | ||
logger.debug(f"Proxy {proxy} success") | ||
return response | ||
else: | ||
logging.debug(f"Proxy {proxy} failed: {response.status_code}: {response.text}") | ||
logger.debug(f"Proxy {proxy} failed: {response.status_code}: {response.text}") |