Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest code upload error #121

Closed
sskaje opened this issue Oct 9, 2019 · 3 comments · Fixed by #123
Closed

Latest code upload error #121

sskaje opened this issue Oct 9, 2019 · 3 comments · Fixed by #123

Comments

@sskaje
Copy link

sskaje commented Oct 9, 2019

Error:
Uploading JPG or ZIP get HTTP 500

AttributeError: 'InMemoryUploadedFile' object has no attribute 'peek'
AttributeError: 'TemporaryUploadedFile' object has no attribute 'peek'

I checked Django code, no method named 'peek'.

I reverted code to file name check, everything works.

BTW, I found a peek in PIL/MpegImagePlugin.py, not sure if @timonegk planned to use this or missed some dependencies.

Code:

if f.peek(4) == b'PK\x03\x04': # ZIP file magic number

trace in log:

Internal Server Error: /images/image/upload/1/
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/views/decorators/http.py", line 40, in inner
    return func(request, *args, **kwargs)
  File "/opt/imagetagger/imagetagger/imagetagger/images/views.py", line 192, in upload_image
    if f.peek(4) == b'PK\x03\x04':  # ZIP file magic number
AttributeError: 'TemporaryUploadedFile' object has no attribute 'peek'
@lilioid
Copy link
Member

lilioid commented Oct 10, 2019

Thank you for reporting this. We (the Bit-Bots) are planning to have a team meeting in the next few days meaning we will definitely take a closer look at your issue after that.

@sharedcare
Copy link

sharedcare commented Oct 12, 2019

Same issue here, I change this line to f.read(4) and it works.

@timonegk
Copy link
Member

I am sorry for the caused inconvenience. I replaced the peek method by read and seek(0) in #123. Replacing it by read only should not be sufficient because the file read cursor is advanced by four bytes. seek(0) resets it to the beginning of the file. Thank you for reporting the bug @sskaje @sharedcare, I really don't know how I missed that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants