# African residential proxies in Python

> Set up African residential proxies in Python with Requests: from $0.50/GB, no KYC, crypto, TLS checks and explicit timeouts.

- URL: https://africaproxies.com/guides/python/
- Last updated: 2026-10-15
- Publisher: AfricaProxies (https://africaproxies.com)

One authorised control request for any of the 24 documented African markets, with privately entered credentials and no automatic retry loop.

**Quick answer — How do I use African residential proxies in Python?**

Use African residential proxies in Python by passing generated country-specific credentials to Requests for an authorised HTTPS endpoint. As of 15 October 2026, AfricaProxies traffic starts at $0.50/GB, with no KYC and crypto funding. The example validates TLS, sets connect/read timeouts and stops on refusals, redirects or errors before a bounded test becomes repeated collection.

## Python setup facts

| Attribute | Value |
| --- | --- |
| Gateway | gw.africaproxies.com |
| HTTP(S) port | 7777 |
| Protocol support | HTTP, HTTPS (CONNECT) and SOCKS5 |
| Priority country codes | NG Nigeria; ZA South Africa; KE Kenya; GH Ghana; TZ Tanzania; CI Côte d’Ivoire; SN Senegal; CM Cameroon |
| Connect / read timeouts | 10 / 30 seconds in this example; not total elapsed-time limits |
| Session ceiling | Sticky sessions keep the same IP for the time you set (ttl, in minutes), up to 30 minutes. The IP can change earlier, for example if the residential device goes offline. |
| Rate | From $0.50/GB |
| Traffic | Usage counts all data sent and received through the proxy (upload and download, headers included). 1 GB = 1,000,000,000 bytes. Connection attempts that fail before reaching the target are not counted. |

## How do I make the first African proxy request in Python?

1. **Prepare a controlled endpoint** — Install Requests in your project environment. Choose a small HTTPS endpoint you own or are permitted to test, and generate the full proxy username for the required African country.
2. **Configure the sample privately** — Supply the generated proxy credentials through the documented configuration. Keep TLS verification enabled, encode credentials for the proxy URL and use explicit connection and read timeouts.
3. **Validate the response** — Run the bounded sample below. Inspect the arriving address in your endpoint log and check that same address in independent location sources; stop on unexpected content, refusals or rate limits.

## What should I prepare before running the example?

Prepare a purchased residential plan and a full proxy username generated for the required country. Choose a small HTTPS endpoint you own or are authorised to test. Install Requests in your project's Python environment with `python -m pip install requests`.

Keep the initial test separate from a marketplace collection. For a Nigerian, Kenyan, Ghanaian or South African application you own, use a small health or QA endpoint and inspect its server log to confirm the arriving exit. The example does not collect marketplace data, place orders or load live paid ads.

*Python: one small authorised HTTPS control request*

```python
from getpass import getpass
from urllib.parse import quote, urlsplit
import requests

country = input("Country to test (ng, za, ke, gh, tz, ci, sn, cm, et, ug, rw, zm, zw, mz, ao, bw, na, bj, tg, bf, ml, mg, mu, cd): ").strip().lower()
if country not in {"ng", "za", "ke", "gh", "tz", "ci", "sn", "cm", "et", "ug", "rw", "zm", "zw", "mz", "ao", "bw", "na", "bj", "tg", "bf", "ml", "mg", "mu", "cd"}:
    raise SystemExit("Choose one country for this example.")

target = input("HTTPS endpoint you own or may test: ").strip()
parts = urlsplit(target)
if parts.scheme != "https" or not parts.hostname or parts.username or parts.password:
    raise SystemExit("Use an authorised HTTPS URL without embedded credentials.")

# Generate this full country-specific username in the client area.
user = getpass("Full generated proxy username: ")
password = getpass("Proxy password: ")
if f"-country-{country}" not in user:
    raise SystemExit("Generate a username for the selected country first.")

proxy = (
    f"http://{quote(user, safe='')}:{quote(password, safe='')}@"
    "gw.africaproxies.com:7777"
)
proxies = {"http": proxy, "https": proxy}

try:
    with requests.Session() as session:
        session.trust_env = False
        with session.get(
            target, proxies=proxies, timeout=(10, 30), verify=True,
            allow_redirects=False, stream=True,
        ) as response:
            if response.status_code in {403, 407, 429}:
                raise SystemExit(f"Stop and diagnose HTTP {response.status_code}; no retry.")
            if 300 <= response.status_code < 400:
                raise SystemExit("Stop: review the redirect destination before requesting it.")
            response.raise_for_status()
            received = 0
            for chunk in response.iter_content(chunk_size=8192):
                received += len(chunk)
                if received > 131072:
                    raise SystemExit("Stop: use a smaller control response.")
            print({"requested_country": country, "status": response.status_code,
                   "body_bytes_read": received})
except requests.exceptions.RequestException as error:
    # Exception messages can expose URLs: print the class, not credentials or URLs.
    raise SystemExit(f"Connection failed: {type(error).__name__}; diagnose before retrying.")

```

## Why are proxies, certificates and timeouts explicit?

Explicit per-request proxy settings prevent ambient proxy settings from selecting a different route; `trust_env = False` also disables environment-derived settings. `quote(..., safe='')` encodes credential components before they enter the proxy URL. The code never prints that URL.

TLS verification remains enabled. In a managed environment that needs a custom certificate bundle, configure the correct trusted bundle rather than disabling verification. The timeout pair limits connection establishment and read waiting; it is not a total runtime deadline. These choices follow the [Requests advanced documentation](https://requests.readthedocs.io/en/latest/user/advanced/) and [API reference](https://requests.readthedocs.io/en/latest/api/).

## How can I check that the exit belongs to the requested country?

Use the source address observed by your own test endpoint, then check that same address against two separately sourced geolocation datasets, for example [IPinfo](https://ipinfo.io/developers) and [DB-IP](https://db-ip.com/api/). Apply each provider's access rules and record the country result, database or service name and time. Two interfaces using the same underlying dataset are not independent evidence.

If you instead call two endpoints that each detect the caller's IP, rotating connections may give them different exits. Compare the same observed address or use a documented sticky session. A disagreement should pause a location-sensitive comparison; neither result proves a physical address.

## How should an African application test use sessions and errors?

A country comparison should preserve its market settings and cookie state separately for each market. Requests sessions can reuse connections, so several page requests do not imply several different exits. Rotating mode: each new connection gets an IP from the pool, usually a different one. To get a new IP on every request, send one request per connection (turn off keep-alive). Sticky mode keeps one IP for the session time you set. The [glossary](/glossary/) explains the difference between the proxy session and application cookies.

A 200 response still needs to contain the expected result; an access challenge can appear with a success status. Stop on unexpected content, refusals or rate limits. The example has no automatic retry configuration and reviews redirects before following them. When the control route works but the target does not, preserve that distinction in a support report.

## Python setup questions

### Can I use one Python session for several countries?

A session can retain cookies and reuse connections. Use separate documented runs for Nigeria, South Africa, Kenya and Ghana so country settings and application state do not mix. A reused connection can keep its exit; do not interpret each `.get()` call as guaranteed rotation.

### Why is the password URL-encoded?

The proxy URL contains credential components. Characters such as `@`, `:` or `/` can otherwise alter how it is parsed. The sample encodes both username and password and never prints the completed URL. Enter secrets at the private prompts instead of committing them to source.

### Why not disable TLS verification for a failed test?

Certificate verification protects the HTTPS target connection. Keep it enabled and diagnose the certificate chain or required trust bundle. Disabling it would hide the cause and change the security of the test rather than confirm that the African route is configured correctly.

### Does the timeout pair cap the whole job at 40 seconds?

No. The example gives separate connect and read waiting limits. Requests documents that those values are not total wall-clock deadlines. The response is also bounded to a small body for this control test; larger project work needs its own explicit budget and permitted scope.

### Should I retry a 403 or 429 through a different exit?

No. The sample stops so the refusal or rate limit can be reviewed. Check the target's permitted access method and your authorised workload. A different country or IP is not permission to continue collection after refusal. Preserve the response for the project's access review.

### How do I confirm country evidence is independent?

Start with one observed exit address and compare its country in two distinct datasets. Record the source names and lookup time. Calling two rotating detector endpoints can observe different addresses, so that procedure would not validate the same exit. Pause a city-sensitive test if evidence disagrees.

## Primary setup references checked on 14 October 2026

1. [Requests advanced usage: proxies, sessions, TLS and timeouts](https://requests.readthedocs.io/en/latest/user/advanced/) — Requests (2026-10-14)
2. [Requests developer interface](https://requests.readthedocs.io/en/latest/api/) — Requests (2026-10-14)
3. [Python urllib.parse: URL component quoting](https://docs.python.org/3/library/urllib.parse.html) — Python Software Foundation (2026-10-14)
4. [IPinfo developer resource](https://ipinfo.io/developers) — IPinfo (2026-10-14)
5. [DB-IP geolocation API](https://db-ip.com/api/) — DB-IP (2026-10-14)

---

AfricaProxies: AfricaProxies is a residential proxy provider for sub-Saharan Africa, paid in crypto with no ID upload.
