AttributeError: 'NoneType' object has no attribute 'tell'

I am trying to write an app that will receive image from my system and detcted the faces in the picture, when i upload image and try to process it, i have this error which is referencin streamlit imghdr.
as shown below

File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/”, line 322, in _run_script
exec(code, module.dict)
File “/root/face/”, line 86, in
File “/root/face/”, line 29, in main
File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/”, line 121, in wrapped_method
return dg._enqueue_new_element_delta(marshall_element, delta_type, last_index)
File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/”, line 342, in _enqueue_new_element_delta
rv = marshall_element(
File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/”, line 119, in marshall_element
return method(dg, element, *args, **kwargs)
File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/”, line 1492, in image
image, caption, width, element.imgs, clamp, channels, format
File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/elements/”, line 230, in marshall_images
(data, mimetype) = _normalize_to_bytes(data, width, format)
File “/root/.virtualenvs/deep/lib/python3.6/site-packages/streamlit/elements/”, line 101, in _normalize_to_bytes
ext = imghdr.what(None, data)
File “/usr/lib/python3.6/”, line 19, in what
location = file.tell()

this is my code

# import the needed pacakages
import streamlit as st
from PIL import Image  # ImageEnhance
import numpy as np 
import cv2

config_path = "deploy.prototxt.txt"
weight_path = "res10_300x300_ssd_iter_140000.caffemodel"

def main():

""" This is face recognition place site """
st.title("Face App")
st.text(" Streamlit Face App with Opencv")
activities = ["Image", "Video"]
choice = st.sidebar.selectbox("Select the app to run", activities)
image_file = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])
if image_file is not None:
    image =
    st.text("original Image")
    if choice == 'Image':
        if st.button("process"):
            result = image_face(image)  
        if choice == 'Video':                                                             
            None  # video_face()

def image_face(image):
    net = cv2.dnn.readNetFromCaffe(config_path, weight_path)
    image = np.array(image)
    (h, w) = image.shape[:2]
    blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)),
                                 1.0, (300, 300), (104.0, 177.0, 123.0))
   detections = net.forward()
    # loop over the detections
    for i in range(0, detections.shape[2]):
        confidence = detections[0, 0, i, 2]  
        if confidence > 0.5:
            # compute the (x, y)-coordinates of the bounding box for the                  
             box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
            (startX, startY, endX, endY) = box.astype("int")
            # draw the bounding box of the face along with the associated     
            text = "{:.2f}%".format(confidence * 100)
            y = startY - 10 if startY - 10 > 10 else startY + 10
            cv2.rectangle(image, (startX, startY), (endX, endY),
                          (0, 0, 255), 2)                                                
            cv2.putText(image, text, (startX, y),
            cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 255), 2)

# def video_face():

if __name__ == '__main__':

Hi @ogahozy,

I believe you forgot to return the image variable from the image_face function. And since the function returns None, a call to st.image(None) will produce the above error.

We will try to improve st.image error messages.
Thanks for using Streamlit!



AttributeError means that there was an Error that had to do with an Attribute request. In general, when you write x.y, y is the purported attribute of x. NoneType means that instead of an instance of whatever Class or Object you think you’re working with, you’ve actually got None. That usually means that an assignment or function call up failed or returned an unexpected result.

mylist = mylist.sort()

The sort() method of a list sorts the list in-place, that is, mylist is modified. But the actual return value of the method is None and not the list sorted. So you’ve just assigned None to mylist. If you next try to do, say, mylist.append(1) Python will give you this error.