赞
踩
python - write() argument must be str, not bytes
源代码
- import requests
- r = requests.get('https://www.baidu.com/img/bd_logo1.png')
- if r.status_code == 200:
- with open('baidu.png','w') as f:
- f.write(r.content)
- else:
- print('获取失败')
修改后代码
- import requests
- r = requests.get('https://www.baidu.com/img/bd_logo1.png')
- if r.status_code == 200:
- with open('baidu.png','wb') as f:
- f.write(r.content)
- else:
- print('获取失败')
-
- # 原因分析 open的modle设置错误,需要将'w'改为'wb' ,'b'代表允许操作字节
-
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。