如何修复Python3中LinkFinder工具的ssl.PROTOCOL_TLSv1_2已弃用警告?
I ran into this exact warning a while back when using LinkFinder—here's how to fix it cleanly:
The warning comes from line 133 in linkfinder.py, where the code explicitly initializes an SSL context with ssl.PROTOCOL_TLSv1_2—a constant that's been deprecated in newer Python releases because hardcoding specific TLS versions isn't secure or future-proof.
Here are two solid solutions, starting with the best practice:
1. Use Python's Default Secure SSL Context (Recommended)
This is the safest and simplest fix. Python's create_default_context() method automatically uses the most secure TLS versions supported by your system, eliminating the need to hardcode a deprecated protocol.
- Open your
linkfinder.pyfile and navigate to line 133:sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) - Replace that line entirely with:
sslcontext = ssl.create_default_context() - Save the file, run LinkFinder again, and the warning should be gone. Bonus: You'll be using a more secure SSL setup than before.
2. Explicitly Use a Supported TLS Protocol (If You Need Control)
If you have a specific reason to enforce a range of TLS versions (e.g., testing against older servers), you can use non-deprecated constants instead:
- For client-side connections (which LinkFinder uses), replace line 133 with:
sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) # Optional: Lock down TLS versions if required sslcontext.min_version = ssl.TLSVersion.TLSv1_2 sslcontext.max_version = ssl.TLSVersion.TLSv1_3 - This uses a supported protocol constant while still letting you define acceptable TLS versions if needed.
Quick Background
Python deprecated ssl.PROTOCOL_TLSv1_2 because modern security practices prioritize letting the client and server negotiate the highest secure TLS version they both support. Using create_default_context() handles this negotiation automatically, so you don't have to worry about outdated protocols.
内容的提问来源于stack exchange,提问作者kylojshan

