Way to convert image straight from URL to base64 without saving as a file in Python Way to convert image straight from URL to base64 without saving as a file in Python python python

Way to convert image straight from URL to base64 without saving as a file in Python


Using the requests library:

import base64import requestsdef get_as_base64(url):    return base64.b64encode(requests.get(url).content)


Since requests is not an official package, I prefer to use urllib.

from urllib.request import urlopen import base64base64.b64encode(urlopen("http://xxx/yyy/abc.jpg").read())