小编isa*_*c.t的帖子

Python 3.7 - 下载图像 - Urllib.request.urlretrieve 错误

我对编程真的很陌生,目前正在 Youtube 上学习 python(“新波士顿 - Python 3”)试图根据视频中显示的代码从互联网下载图像,但弹出错误。这是代码:

import random
import urllib.request

def download_web_image(url):
    name = random.randrange(1,1000)
    full_name = str(name) + '.gif'  #str convert number to word
    urllib.request.urlretrieve(url, full_name)

download_web_image ('https://images.freeimages.com/images/large-previews/ed3/a-stormy-paradise-1-1563744.jpg')
Run Code Online (Sandbox Code Playgroud)

和错误:

回溯(最近一次调用最后一次):
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py”,第 1317 行,在 do_open 中
    encode_chunked=req.has_header('传输编码'))
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1229 行,请求中
    self._send_request(方法、url、正文、标头、encode_chunked)
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1275 行,在 _send_request 中
    self.endheaders(正文,encode_chunked=encode_chunked)
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1224 行,在结尾标题中
    self._send_output(message_body,encode_chunked=encode_chunked)
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1016 行,位于 _send_output
    自发送(msg)
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 956 行,发送
    self.connect()
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py”,第 1392 行,在连接中
    服务器主机名=服务器主机名)
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第412行,在wrap_socket中
    会话=会话
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 853 行,在 _create 中
    self.do_handshake()
  文件“/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py”,第 1117 行,在 do_handshake 中
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败:证书链中的自签名证书(_ssl.c:1056) …

python-3.x

7
推荐指数
1
解决办法
2923
查看次数

标签 统计

python-3.x ×1