requests获取网络图片后直接转为base64

1 import requests
2 import base64
3 
4 
5 def get_url_image(url):
6     r = requests.get(url)
7     base_data = base64.encodebytes(r.content)
8     return 'data:image/png;base64,%s' % base_data