diff --git a/openedx/core/djangoapps/profile_images/images.py b/openedx/core/djangoapps/profile_images/images.py index aefb28e8b7..bfce3a026f 100644 --- a/openedx/core/djangoapps/profile_images/images.py +++ b/openedx/core/djangoapps/profile_images/images.py @@ -3,6 +3,7 @@ Image file manipulation functions related to profile images. """ from __future__ import absolute_import +import binascii from collections import namedtuple from contextlib import closing from io import BytesIO @@ -128,7 +129,7 @@ def validate_uploaded_image(uploaded_file): # check magic number matches expected file type headers = IMAGE_TYPES[filetype].magic - if uploaded_file.read(len(headers[0]) / 2).encode('hex') not in headers: + if binascii.hexlify(uploaded_file.read(len(headers[0]) // 2)).decode('utf-8') not in headers: file_upload_bad_ext = _( u'The file name extension for this file does not match ' u'the file data. The file may be corrupted.'