I would like to screenshot without saving the photo and transform it into base64 to save it in a dictionary.
def screen(): global photo, numero_photo, photo_temporaire, photo_save time.sleep(3) position_screen = pyautogui.position() photo = pyautogui.screenshot(region = (position_screen[0] - 20, position_screen[1] - 20, 40, 40)) with open(photo, 'rb') as imagefile: format_byte = base64.b64encode(imagefile.read()) format_byte = str(format_byte) format_byte = format_byte.lstrip("b'") format_byte = format_byte.rstrip("'") photo_save.append(format_byte) print(photo_save) and I have this error:
File "D:\Logiciel\Python\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "d:\Logiciel\programme\projet_bouclette\testbase64_7.py", line 23, in screen with open(photo, 'rb') as imagefile: TypeError: expected str, bytes or os.PathLike object, not Image