Skip to content

Commit

Permalink
0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoloboschi committed Sep 4, 2024
1 parent 640a56c commit 1fe7c67
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
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"
Expand Down
16 changes: 6 additions & 10 deletions requests_anon/__init__.py
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}")

0 comments on commit 1fe7c67

Please sign in to comment.