0

I'm trying to get an image. Here is my code.

import io
import ssl
from urllib import request
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

item_image = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/180px-Cat03.jpg"
    
f = io.BytesIO(request.urlopen(item_image,context=context).read())   

When I try this code, warning appiers

C:\Users\xxx\AppData\Local\Temp\ipykernel_7868\2896668910.py:4: DeprecationWarning: ssl.PROTOCOL_TLSv1_2 is deprecated
  context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)

I referred to this answer. Python3 "DeprecationWarning: ssl.PROTOCOL_TLSv1_2 is deprecated sslcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)" error

So I tried to replace "ssl.PROTOCOL_TLSv1_2" to "ssl.PROTOCOL_TLS_CLIENT" or "ssl.PROTOCOL_TLS_SERVER"

but both does not work. I've read document but I can not understand.https://docs.python.org/3/library/ssl.html

What shoud I do to clear this worning?

I just mentioned the above settings in this question but still if more code is required then tell me I'll update my question with that information. Thank you

daylyroppo3
  • 79
  • 1
  • 9

1 Answers1

1

Mostly it is a matter of python configuration semantics (TLSv1.2 is still current, and supported by wikipedea), it's just the configuration approach has changed. Try:

context = ssl.SSLContext( ssl.PROTOCOL_TLS_CLIENT )
context.minimum_version = ssl.TLSVersion.TLSv1_2
context.maximum_version = ssl.TLSVersion.TLSv1_3
Buffoonism
  • 1,669
  • 11
  • 11
  • Thank you for answering but still error occurs. URLError: What should I do? – daylyroppo3 Sep 02 '22 at 04:19
  • Sounds like the certs aren't available. Is it this issue? https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error – Buffoonism Sep 02 '22 at 05:02