Home >Backend Development >Python Tutorial >About urllib3's ssl.SSLError(f\'read error: {e!r}\') from e
urllib3 is a library used to process URLs in python. It can be used to send Httpask. ssl.SSLError(f"read error: {e!r}") is an error indicating that something went wrong while using urllib3. This error may be due to a network connection problem, or because the connected website uses certificate verification and the client fails to pass the verification. In addition, certificate verification may fail because the certificate has expired or the certificate is not issued by a trusted CA.
For this error, you can take the following methods to solve it:
Make sure the network connection is normal, try to reconnect or change the network.
Use verify = False to disable certificate verification, but doing so will make the connected website insecure
Use other libraries in the code to send requests, such as requests . Use the appropriate certificate for verification. If it is a self-signed certificate, you can import it into the program. Use a custom CA certificate for verification. If it is Because of errors caused by certificate expiration, you need to update the certificateIt should be noted that using the second method can solve the problem, but it will make the website connection unsafe. Therefore, it is better to use other methods to solve the problem. Usage examplesOf course. The following is sample code to disable certificate verification when sendinghttps requests using the urllib3 library:
import urllib3 http = urllib3.PoolManager() response = http.request('GET', 'https://example.com', verify=False) print(response.data)The following is sample code to disable certificate verification when sending https requests using the requests library:
import requests response = requests.get('https://example.com', verify=False) print(response.text)The following is sample code for using custom certificate verification when sending https requests using the requests library:
import requests response = requests.get('https://example.com', verify='path/to/ca_cert.pem') print(response.text)It should be noted that when using custom certificate verification, the certificate file must be in PEM format and the path must be correct. It should also be noted that if the error is caused by certificate expiration, then the certificate needs to be updated.
The above is the detailed content of About urllib3's ssl.SSLError(f\'read error: {e!r}\') from e. For more information, please follow other related articles on the PHP Chinese website!