相关疑难解决方法(0)

如何使用请求下载图像

我正在尝试使用python的requests模块从Web下载并保存图像.

这是我使用的(工作)代码:

img = urllib2.urlopen(settings.STATICMAP_URL.format(**data))
with open(path, 'w') as f:
    f.write(img.read())
Run Code Online (Sandbox Code Playgroud)

以下是使用以下内容的新(非工作)代码requests:

r = requests.get(settings.STATICMAP_URL.format(**data))
if r.status_code == 200:
    img = r.raw.read()
    with open(path, 'w') as f:
        f.write(img)
Run Code Online (Sandbox Code Playgroud)

你能帮助我从响应中使用什么属性requests吗?

python urllib2 python-requests

336
推荐指数
13
解决办法
34万
查看次数

标签 统计

python ×1

python-requests ×1

urllib2 ×1