ValueError: check_hostname requires server_hostname
时间: 2023-10-23 17:13:39 浏览: 46
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".
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)