我正在尝试使用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
吗?