diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 1015865..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: CI -on: - pull_request: - branches: - - main - -concurrency: - group: ci-${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - unit-tests: - name: Unit Tests - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: "Setup: Python 3.11" - uses: actions/setup-python@v4 - with: - python-version: "3.11" - cache: "pip" - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install poetry - - - name: Run unit tests - run: | - poetry install - poetry run pytest \ No newline at end of file diff --git a/README.md b/README.md index 86a7bce..9271ecb 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,12 @@ pip install requests-anon ```python import requests -from requests_anon import request_with_anon_proxy_unsafe +from requests_anon import anon_request # this one will contact the server directly response = requests.get("https://google.com") # this one will contact the server using an anonymous proxy -response = request_with_anon_proxy_unsafe("get", "https://google.com") +response = anon_request("get", "https://google.com") ``` ## Considerations diff --git a/pyproject.toml b/pyproject.toml index 05adf50..182dd64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] readme = "README.md" diff --git a/requests_anon/__init__.py b/requests_anon/__init__.py index 13e87f9..d5ee253 100644 --- a/requests_anon/__init__.py +++ b/requests_anon/__init__.py @@ -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}")