OpenCV imdecode returns none

I’m trying to read an image from url. For this, I created the funcion below. For some url I input, it works exactly how I wish, but for others, it doesn’t. In this cases the cv2.imread(img, cv2….