import string from urllib.parse import quote # 将url中带的中文进行转码,而特殊符号不变 src = quote(src, safe=string.printable) img = urlopen(src).read()
例如:link = 'http://jingkids.com/wp-content/uploads/2018/10/平和青浦-for-web-1024x553.jpg'
src = quote(link , safe=string.printable)
输出的src 就是:http://jingkids.com/wp-content/uploads/2018/10/%E5%B9%B3%E5%92%8C%E9%9D%92%E6%B5%A6-for-web-1024x553.jpg