-1

I copied the answer to this stack overflow quesiton Decoding base64 from POST to use in PIL ie:

from PIL import Image
from io import BytesIO
import base64

data['img'] = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==''' 

im = Image.open(BytesIO(base64.b64decode(data)))

and ran it in my text editor and keeps saying data is undefined but I can't figure out why.

Bob
  • 279
  • 6
  • 13

2 Answers2

2

Remove ['img']

from PIL import Image
from io import BytesIO
import base64

data = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==''' 

im = Image.open(BytesIO(base64.b64decode(data)))
Daniele Cappuccio
  • 1,952
  • 2
  • 16
  • 31
0

Just add data = dict() before the data['img'] = .... data need to be define as a dict before you can access the dict key with the bracket operator.

TwistedSim
  • 1,960
  • 9
  • 23