首页 > urllib.request.urlretrieve下载错误

urllib.request.urlretrieve下载错误

一个用来下载图片的函数,保证url是有效的,在执行到urlretrieve时发生崩溃,不太理解HTTP 461是什么错误

file_name = "/Users/wz/Desktop/heroes face new/hero-" + str(item['id']) + item['name'] + '.png'
urllib.request.urlretrieve(item['url'], str(file_name))//这里崩溃
print(file_name, '写入成功')

报如下的错误

urllib.error.HTTPError: HTTP Error 461:

错误详细信息

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1531, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 938, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/wz/PycharmProjects/装备/main.py", line 204, in <module>
    three_hundred_hero.get_png(data)
  File "/Users/wz/PycharmProjects/装备/main.py", line 45, in get_png
    urllib.request.urlretrieve(item['url'], str(file_name))
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 188, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/Users/wz/anaconda/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 461: 

我也遇到了同样的问题,只不过我的是HTTP Error 414:
希望能给个解决这种问题的思路


网址有问题吧

【热门文章】
【热门文章】