ValueError: check_hostname requires server_hostname
时间: 2023-10-23 10:15:17 浏览: 30
This error occurs when the check_hostname parameter is set to True for an HTTPS connection, and the server_hostname parameter is not provided.
To fix this error, you need to provide the server hostname when making the HTTPS connection. You can do this by adding the server_hostname parameter to the HTTPSConnection or HTTPSHandler object.
For example:
```python
import http.client
conn = http.client.HTTPSConnection("example.com", port=443, timeout=10, check_hostname=True, server_hostname="example.com")
conn.request("GET", "/")
response = conn.getresponse()
print(response.read().decode())
conn.close()
```
In this example, we provide the server_hostname parameter as "example.com" when creating the HTTPSConnection object. This ensures that the check_hostname parameter works correctly and the connection is established without any errors.
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)