ValueError: check_hostname requires server_hostname
时间: 2023-10-23 16:13:39 浏览: 96
This error occurs when the `check_hostname` argument is set to `True` in the `HTTPSConnection` or `HTTPConnection` constructor, but the `server_hostname` argument is not provided.
The `check_hostname` argument is a security feature that ensures the hostname in the server's SSL/TLS certificate matches the hostname of the server that the client is connecting to. This prevents man-in-the-middle attacks.
To fix this error, you need to provide the `server_hostname` argument when creating the connection object. The `server_hostname` should be the hostname of the server that the client is connecting to.
For example:
```
import http.client
conn = http.client.HTTPSConnection("example.com", port=443, timeout=10, check_hostname=True, server_hostname="example.com")
```
In this example, we are creating an HTTPS connection to "example.com" on port 443, with a timeout of 10 seconds, and with `check_hostname` set to `True`. We also provide the `server_hostname` argument with the value "example.com".
阅读全文