TypeError: path should be path-like or io.BytesIO, not <class 'NoneType'>

hi
I am new to Streamlit and programming.
I keep getting this error message in my app.py.
Can you help ?

line 31 : image = image.load_img(uploaded_file)
buffer = io.BytesIO() # create file in memory
image.save(buffer, ‘jpeg’) # save in file in memory - it has to be jpeg, not jpg
buffer.seek(0) # move to the beginning of file
bg_image = buffer # use it without open()

error message:
2022-07-27 12:25:15.189 Uncaught app exception
Traceback (most recent call last):
File “C:\Users\yeong\anaconda3\envs\IOD_9thMay2022\lib\site-packages\streamlit\scriptrunner\script_runner.py”, line 557, in _run_script
exec(code, module.dict)
File “app.py”, line 31, in
image = image.load_img(uploaded_file)
File “C:\Users\yeong\anaconda3\envs\IOD_9thMay2022\lib\site-packages\keras\utils\image_utils.py”, line 396, in load_img
raise TypeError(‘path should be path-like or io.BytesIO’
TypeError: path should be path-like or io.BytesIO, not <class ‘NoneType’>

Make sure uploaded_file is not None.

1 Like

I can display the uploaded file.

Not sure what you mean by that. The error message is telling you that uploaded_file is None when you call image.load_img(uploaded_file) in line 31.

Okay. Thanks. Let me check

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.