【发布时间】:2021-12-15 08:18:41
【问题描述】:
我正在尝试从 Internet 读取图像 URL 并能够通过 python 将图像获取到我的机器上,我使用了此博客文章中使用的示例https://www.geeksforgeeks.org/how-to-open-an-image-from-the-url-in-pil/,它是https://media.geeksforgeeks.org/wp-content/uploads/20210318103632/gfg-300x300.png,但是,当我尝试我的自己的例子它似乎不起作用我已经尝试了 HTTP 版本,但它仍然给我 403 错误。有谁知道可能是什么原因?
import urllib.request
urllib.request.urlretrieve(
"http://image.prntscr.com/image/ynfpUXgaRmGPwj5YdZJmaw.png",
"gfg.png")
输出:
urllib.error.HTTPError:HTTP 错误 403:禁止
【问题讨论】:
-
尝试将用户代理设置为 firefox 或 chrone
标签: python python-requests urllib urllib2 http-status-code-403