---
title: "SOCKS5 vs. SOCKS5h in Python Requests: 5 DNS Checks · KimiData"
description: "Learn where Requests resolves DNS with socks5 and socks5h, configure a SOCKS proxy safely, verify the exit IP and DNS path, and troubleshoot common failures."
url: "https://kimidata.com/blog/socks5-vs-socks5h-python-requests"
language: "en"
---

# SOCKS5 vs. SOCKS5h in Python Requests: Where Does DNS Resolve?

> Learn where Requests resolves DNS with socks5 and socks5h, configure a SOCKS proxy safely, verify the exit IP and DNS path, and troubleshoot common failures.

If a Python Requests call succeeds through a SOCKS proxy but still sends DNS lookups from your machine, the proxy URL scheme may be the reason. Requests distinguishes `socks5://` from `socks5h://`: the first resolves the destination hostname on the client, while the second sends that hostname to the proxy for remote resolution. This difference matters when you need the destination lookup to follow the proxy route, when your local network cannot resolve a target, or when you are checking for DNS exposure. This guide shows how to configure either scheme, choose the right one for a task, verify what happened, and troubleshoot cases where the result does not match expectations.

 

## SOCKS5 vs. SOCKS5h in Python Requests: the DNS difference

 

In Requests, the scheme at the start of the **proxy URL** controls where the destination hostname is resolved:

 

| Proxy URL scheme | Where the destination hostname is resolved | What the SOCKS proxy receives |
| --- | --- | --- |
| `socks5://` | On the client running Python | An IP address for the destination |
| `socks5h://` | Through the proxy-side resolution path | The destination hostname |

 

The `h` suffix is a convention used by Requests and its SOCKS transport stack to request remote hostname resolution. It does not mean a different proxy product or a separate version of SOCKS. SOCKS5 itself can carry a domain name as the requested destination; the client library decides whether to resolve the name first or send it as a name. The [SOCKS5 specification, RFC 1928](<https://www.rfc-editor.org/rfc/rfc1928.html>), defines address types for IPv4, IPv6, and domain names. Requests documents the URL-scheme behavior in its [advanced usage guide](<https://requests.readthedocs.io/en/stable/user/advanced/>), and [urllib3's SOCKS documentation](<https://urllib3.readthedocs.io/en/stable/reference/contrib/socks.html>) describes local-DNS `socks5://` and remote-DNS `socks5h://` modes.

 

A practical default is to use `socks5h://` when you want the destination hostname sent through the proxy. Use `socks5://` when client-side resolution is intentional, such as when you need your own resolver's answer and have confirmed that local DNS is appropriate. Neither choice encrypts DNS by itself or makes a request anonymous. `socks5h` changes the destination-resolution path; the proxy operator still receives the hostname, and other parts of your application or operating system may make separate DNS requests.

 

There is also an important exception: if the URL contains a literal destination IP address instead of a hostname, there is no destination DNS lookup for the SOCKS scheme to move. The hostname of the proxy gateway itself may still need to be resolved locally so Python can connect to that gateway.

 

## Configure SOCKS5h in Requests

 

Requests needs its optional SOCKS dependency. Install it in the same virtual environment that runs your script:

 

```bash
python -m pip install "requests[socks]"
```

 

For a reproducible setup, keep credentials outside source control. The example below reads placeholders from environment variables, percent-encodes the username and password for use in a URL, and uses one proxy URL for HTTP and HTTPS destinations.

 

```python
import os
from urllib.parse import quote

import requests

host = os.environ["YOUR_HOST"]
port = os.environ["YOUR_PORT"]
username = quote(os.environ["YOUR_USERNAME"], safe="")
password = quote(os.environ["YOUR_PASSWORD"], safe="")

proxy_url = f"socks5h://{username}:{password}@{host}:{port}"

session = requests.Session()
session.trust_env = False
session.proxies.update({
    "http": proxy_url,
    "https": proxy_url,
})

response = session.get("https://ipinfo.io/json", timeout=(10, 30))
response.raise_for_status()
print(response.json())
```

 

Set `YOUR_HOST`, `YOUR_PORT`, `YOUR_USERNAME`, and `YOUR_PASSWORD` in your local environment to the values supplied by your proxy service. Do not paste real credentials into a public script, issue, notebook, or screenshot. Percent-encoding matters if a username or password contains characters such as `@`, `:`, `/`, or `#`; without encoding, those characters can be mistaken for URL separators.

 

The `proxies` dictionary keys, `http` and `https`, refer to the scheme of the **destination URL**. The value is the proxy URL and can begin with `socks5h://`. In other words, an HTTPS website can be requested through a SOCKS5 proxy without changing the destination from `https://`. The HTTPS connection still uses TLS between the client and destination, subject to the proxy route and normal certificate validation.

 

Setting `session.trust_env = False` makes this example easier to reason about because Requests will not inherit proxy settings from environment variables. It also means environment-based settings such as custom CA bundle paths are not inherited. If your environment intentionally depends on those settings, retain them and inspect `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, and `NO_PROXY` instead of disabling environment trust. Requests documents both proxy dictionaries and environment-based configuration in its [proxy settings section](<https://requests.readthedocs.io/en/stable/user/advanced/#proxies>).

 

The response from `https://ipinfo.io/json` should contain an IP address for the connection as seen by that service, along with location-related fields. The returned IP helps confirm that the request reached the IP-echo endpoint through an egress route different from your direct connection. It does **not** prove where DNS was resolved. Check the route and DNS behavior as separate things.

 

## When to choose socks5 or socks5h

 

Choose `socks5h://` when the destination should be resolved along the proxy-side path. This is useful when your client network cannot resolve a hostname, when region-specific DNS answers are relevant to a test, or when you want to avoid sending the target's ordinary DNS query from the client network. The precise resolver used after the hostname reaches the proxy depends on the proxy service's implementation and upstream DNS configuration.

 

Choose `socks5://` when local DNS is part of the intended design. For example, an engineering team might need to resolve a private or split-horizon hostname using its own network resolver and then route a reachable destination IP through a SOCKS proxy. Confirm that the proxy can reach that address and that routing to it is permitted. If the client resolves a public hostname to an address that is not reachable from the proxy network, the connection can fail even though DNS succeeded.

 

For a target written as an IP literal, such as `https://203.0.113.10/`, neither scheme performs a DNS lookup for that target. This can be useful for a controlled network test, but it is not a general substitute for hostname-based HTTPS testing: certificates and virtual hosting often depend on the intended hostname.

 

Remote resolution is not a universal privacy guarantee. A process may make DNS requests before Requests handles the call, another library may use its own resolver, and a hostname entered as the proxy gateway still has to be resolved to reach the proxy. Keep the test narrowly scoped to the Requests request you are evaluating.

 

## Verify the proxy route and DNS path separately

 

First check the route. Run the example against an IP-echo endpoint and compare the returned IP with the direct connection's IP. If the values are the same, confirm that the request used the configured session, that the proxy host and port are correct, and that no environment or application configuration replaced the proxy.

 

Then verify how the destination name was handed to the SOCKS proxy. A public IP-check page cannot tell you whether the client or proxy performed DNS resolution. For a controlled test, use a test SOCKS server or proxy with request logging and inspect the destination address type in its SOCKS connection request. With a hostname target, the `socks5h` path should send the hostname; a `socks5` path should send an address already resolved by the client. In RFC 1928, the address type field distinguishes a domain name from IPv4 or IPv6.

 

Use this five-check sequence when validating a new setup:

 

1. Confirm the destination is a hostname, not an IP literal, and that the proxy URL begins with the intended scheme.
2. Check whether Requests is inheriting `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`, or `NO_PROXY`; isolate the session or inspect those settings deliberately.
3. Use a controlled SOCKS endpoint or proxy log to confirm whether the destination arrives as a hostname or an IP address.
4. If you control the destination domain, send a request to a unique test subdomain and review its DNS logs alongside client-side observations.
5. Check the exit IP separately with an IP-echo service; do not treat that result as proof of remote DNS.

 

If you operate the destination domain, a unique test subdomain and authoritative DNS logs can add evidence about when a lookup occurs. Avoid relying on a single public “DNS leak test” as proof for one Python call: browser tests measure the browser's behavior, while this question concerns the Requests process. A packet capture on the client can also help, but encrypted DNS, cached answers, and background processes can make the capture incomplete or misleading. For production assurance, combine a controlled proxy-side log or SOCKS test with client-side observation.

 

A small comparison is useful during diagnosis:

 

| Test result | What it tells you | What it does not tell you |
| --- | --- | --- |
| Exit IP differs from direct IP | The IP-echo request likely used a different network exit | Whether the target hostname was resolved locally |
| Proxy log records a domain destination | The client sent a hostname to the SOCKS proxy | Which upstream resolver answered it |
| Local DNS capture shows no target query | No matching local query was observed during the capture | That no other resolver path or cached lookup was used |
| Request succeeds with `socks5h` only | Remote resolution may have avoided a client-side lookup problem | That the proxy's DNS answer is globally authoritative or always stable |

 

## Troubleshoot common Requests SOCKS errors

 

**“Missing dependencies for SOCKS support.”** Install `requests[socks]` using the Python executable for the same virtual environment, then restart the process. If you installed it in a different environment, the running interpreter may still be unable to import the SOCKS dependency.

 

**407 Proxy Authentication Required.** A 407 response indicates that the proxy requires authentication or did not accept the supplied credentials. Recheck the username, password, host, port, and any provider-specific username parameters. If credentials include reserved URL characters, percent-encode them as shown above. Do not repeatedly retry unchanged credentials.

 

**The request times out or the proxy refuses the connection.** Check that the proxy is reachable from the current network, that the port is correct, and that the service supports SOCKS5 for the selected endpoint. A timeout can happen during proxy connection, DNS resolution, or the destination response; use a connect/read timeout tuple and test a known permitted hostname before investigating a target-specific problem.

 

**`socks5h` fails but `socks5` works.** The proxy-side resolver may be unable to resolve the hostname, the proxy may not support the requested remote-DNS behavior, or local environment settings may be changing how the request is routed. Verify the same host and credentials against a controlled SOCKS endpoint. Check whether a `NO_PROXY` rule or application wrapper changes the route. Requests has documented platform-specific proxy-bypass behavior in a [GitHub issue](<https://github.com/psf/requests/issues/6086>); treat that issue as a troubleshooting lead, not as evidence that every current installation is affected.

 

**`socks5` fails but `socks5h` works.** The client may not be able to resolve the target from its current network, or its resolver may return an address that the proxy cannot reach. Compare a hostname request with a controlled IP-literal test, while accounting for TLS hostname and virtual-host requirements.

 

**The exit IP is right, but regional content is unexpected.** DNS is only one input to a website's response. The exit IP, site-side geolocation, account state, cookies, language headers, CDN routing, and the target's own localization rules may affect the result. Confirm the exit IP and country with a suitable checker, then test the actual page behavior separately.

 

## Use SOCKS5h with KimiData only after confirming endpoint behavior

 

KimiData's public [rotating residential proxy page](<https://kimidata.com/proxies/residential>) lists HTTP, HTTPS, and SOCKS5, and describes country/city targeting and rotating or sticky sessions. Its [proxy setup guide](<https://kimidata.com/guides/proxy-setup>) explains how to retrieve gateway details and verify an exit IP. The public product information does not specifically state whether its SOCKS5 endpoint supports remote hostname resolution when a client uses the `socks5h://` scheme.

 

If remote DNS is a requirement, test the exact KimiData endpoint and account configuration with a controlled hostname before using it in a production workflow, or ask support to confirm `socks5h`/remote-DNS compatibility. Do not infer support for `socks5h` solely from a page that lists SOCKS5. If the connection works with ordinary `socks5://` but remote DNS is required, use a proxy endpoint that explicitly confirms remote hostname resolution.

 

When the proxy route is confirmed, KimiData's [proxy checker](<https://kimidata.com/tools/proxy-checker>) can help inspect a proxy connection and exit location. It is a route check, not a substitute for observing DNS behavior from the Requests process. You can also review [current proxy plans](<https://kimidata.com/pricing>) if you need a SOCKS5-compatible endpoint for a permitted data collection or regional testing task.

 

Use proxies only for lawful, authorized requests. Respect the target website's terms, privacy requirements, rate limits, and local law; remote DNS does not grant access to restricted content or change what a site permits.

 

## Frequently asked questions

 

### Does socks5h hide my DNS queries from everyone?

No. It asks the Requests SOCKS stack to send the destination hostname to the proxy for resolution. The proxy operator can see the hostname, and other software or the operating system may make separate DNS queries. It is not an encryption or anonymity guarantee.

 

### Should both entries in the Requests proxies dictionary use socks5h?

If both HTTP and HTTPS destination URLs should use the same remote-DNS SOCKS route, set both the "http" and "https" keys to the same socks5h proxy URL. The keys describe the destination scheme; the value describes the proxy connection.

 

### Will socks5h work if I put an IP address in the destination URL?

There is no hostname lookup for a literal destination IP, so the local-versus-remote DNS choice does not apply to that destination. The hostname of the proxy gateway may still require DNS resolution.

 

### Can ipinfo.io confirm that Requests used remote DNS?

No. An IP-echo response can help confirm the egress IP used for that request, but it does not reveal whether the destination hostname was resolved on the client or through the proxy. Use a controlled SOCKS log or another DNS-specific test.

 

### Why does Requests say SOCKS support is missing after installation?

The optional SOCKS dependency may have been installed into a different Python environment than the one running the script. Activate the correct environment and run python -m pip install "requests\[socks\]" with its interpreter.

**Max**
 Written by the author above and published by KimiData

[View original page](<https://kimidata.com/blog/socks5-vs-socks5h-python-requests>) · [llms.txt](<https://kimidata.com/llms.txt>)
