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

AttributeError: 'NoneType' object has no attribute 'file' #100

Open
n1k0 opened this issue Jul 14, 2016 · 4 comments
Open

AttributeError: 'NoneType' object has no attribute 'file' #100

n1k0 opened this issue Jul 14, 2016 · 4 comments
Labels
stale For marking issues as stale. Labeled issues will be closed soon if label is not removed.

Comments

@n1k0
Copy link

n1k0 commented Jul 14, 2016

kinto-attachment 0.7.1, messing around with the API from js, managed to crash the server with some rotten request:

ERROR:kinto.core.views.errors:"POST  /v1/buckets/custom/collections/plop/records/2f3473f9-8259-4cb3-9ec7-121d151e1a4f/attachment" ? (? ms) 'NoneType' object has no attribute 'file' agent=node-fetch/1.0 (+https://github.com/bitinn/node-fetch) authn_type=basicauth collection_id=record collection_timestamp=1468484695624 errno=110 exception=Traceback (most recent call last):
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 101, in tm_tween
    reraise(*exc_info)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 83, in tm_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/router.py", line 158, in handle_request
    view_name
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/config/views.py", line 182, in __call__
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 393, in attr_view
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 302, in _secured_view
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 442, in rendered_view
    result = view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/cornice/service.py", line 573, in wrapper
    response = view_(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/views/services.py", line 19, in attachment_post
    return post_attachment_view(request, SINGLE_FILE_FIELD)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/views/__init__.py", line 34, in post_attachment_view
    gzipped=gzipped)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/utils.py", line 126, in save_file
    content.file.seek(0)
AttributeError: 'NoneType' object has no attribute 'file' lang=None uid=a9d81e1b56f2b77103e87601621a99b3d82a15abf7c72ce57a032d0964317c7a

I unfortunately can't provide a curl/httpie command for reproducing as fetch doesn't expose such a feature.

@leplatrem
Copy link
Contributor

I'll add a safety check but I couldn't reproduce when investigating #82 (which is likely to be the same)

@leplatrem
Copy link
Contributor

leplatrem commented Jul 14, 2016

The 500 is fixed with current master.

However, when running the integration tests of Kinto/kinto-http.js#115, I get a 400 because the client does not send the proper Content-Type header: Not an HTML form submission (Content-Type: application/json)>. It should be encode multipart, and is done automatically. Will see if I can fix there...

@n1k0
Copy link
Author

n1k0 commented Jul 14, 2016

It should be encode multipart

Makes sense, but now I wonder how it could ever work in the kinto-admin? We definitely don't set this header there.

@n1k0
Copy link
Author

n1k0 commented Jul 14, 2016

Also, if I force the content-type header like this:

diff --git a/src/collection.js b/src/collection.js
index a0ee33c..6ce3f86 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -193,6 +193,10 @@ export default class Collection {
     const addAttachmentRequest = {
       ...updateRequest,
       method: "POST",
+      headers: {
+        ...updateRequest.headers,
+        "Content-Type": "multipart/form-data",
+      },
       body: formData
     };
     return this.client.execute(addAttachmentRequest, {stringify: false});

I'm getting a new server error (using latest kinto-attachment master):

ERROR:kinto.core.views.errors:"POST  /v1/buckets/custom/collections/plop/records/760ce6a9-46f2-4211-a611-88da16151356/attachment" ? (? ms) Invalid boundary in multipart form: b'' agent=node-fetch/1.0 (+https://github.com/bitinn/node-fetch) authn_type=basicauth collection_id=record collection_timestamp=1468495916841 errno=110 exception=Traceback (most recent call last):
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/tweens.py", line 22, in excview_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 101, in tm_tween
    reraise(*exc_info)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/compat.py", line 15, in reraise
    raise value
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid_tm/__init__.py", line 83, in tm_tween
    response = handler(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/router.py", line 158, in handle_request
    view_name
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/view.py", line 547, in _call_view
    response = view_callable(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/config/views.py", line 182, in __call__
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 393, in attr_view
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 371, in predicate_wrapper
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 302, in _secured_view
    return view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 442, in rendered_view
    result = view(context, request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/pyramid/viewderivers.py", line 147, in _requestonly_view
    response = view(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/cornice/service.py", line 573, in wrapper
    response = view_(request)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/views/services.py", line 17, in attachment_post
    return post_attachment_view(request, SINGLE_FILE_FIELD)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/kinto_attachment/views/__init__.py", line 24, in post_attachment_view
    content = request.POST.get(file_field)
  File "/home/niko/work/kinto-http.js/.venv/lib/python3.5/site-packages/webob/request.py", line 801, in POST
    encoding='utf8')
  File "/usr/lib/python3.5/cgi.py", line 559, in __init__
    self.read_multi(environ, keep_blank_values, strict_parsing)
  File "/usr/lib/python3.5/cgi.py", line 687, in read_multi
    raise ValueError('Invalid boundary in multipart form: %r' % (ib,))
ValueError: Invalid boundary in multipart form: b'' lang=None uid=a9d81e1b56f2b77103e87601621a99b3d82a15abf7c72ce57a032d0964317c7a

@alexcottner alexcottner added the stale For marking issues as stale. Labeled issues will be closed soon if label is not removed. label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale For marking issues as stale. Labeled issues will be closed soon if label is not removed.
Projects
None yet
Development

No branches or pull requests

3 participants