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

Error: django.utils.datastructures.MultiValueDictKeyError: '1' #34

Open
fabian-ws opened this issue Oct 18, 2019 · 9 comments
Open

Error: django.utils.datastructures.MultiValueDictKeyError: '1' #34

fabian-ws opened this issue Oct 18, 2019 · 9 comments

Comments

@fabian-ws
Copy link

Hello Imcgartland,

I've been busy all day with trying to upload an image to django by react-native. After reading a lot I landed at graphene-file-upload. Unfortunately, I do not get it to work and I hope you can help.

I get the following error message:

Request Method: POST
http://192.168.2.22:8000/graphql/
2.2.6
MultiValueDictKeyError
'1'
/backend/env/lib/python3.7/site-packages/django/utils/datastructures.py in getitem, line 80
/backend/env/bin/python
3.7.4
['/backend', '/Applications/PyCharm.app/Contents/helpers/pydev', '//backend', '/Applications/PyCharm.app/Contents/helpers/pycharm_display', '/Applications/PyCharm.app/Contents/helpers/third_party/thriftpy', '/Applications/PyCharm.app/Contents/helpers/pydev', '/Library/Caches/PyCharm2019.2/cythonExtensions', '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/usr/local/Cellar/python/3.7.4_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/backend/env/lib/python3.7/site-packages', '/Applications/PyCharm.app/Contents/helpers/pycharm_matplotlib_backend']
Fri, 18 Oct 2019 17:17:42 +0000

My request is the following:

accept: */*
authorization: JWT eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InVsbG1hbm4uaW5AZ21haWwuY29tIiwiZXhwIjoxNTcwNzg0Njk2LCJvcmlnSWF0IjoxNTcwNzg0Mzk2fQ.JOsSqFIkwRw5lrd6easuWeKYES346qzq9_jFbp8m9Vw
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryyhscsCwqLniB9NlA
Origin: file://

------WebKitFormBoundaryyhscsCwqLniB9NlA
Content-Disposition: form-data; name="operations"

{"operationName":"UploadEventPicture","variables":{"file":null},"query":"mutation UploadEventPicture($file: Upload!) {\n  uploadEventPicture(file: $file) {\n    success\n    __typename\n  }\n}\n"}
------WebKitFormBoundaryyhscsCwqLniB9NlA
Content-Disposition: form-data; name="map"

{"1":["variables.file"]}
------WebKitFormBoundaryyhscsCwqLniB9NlA
Content-Disposition: form-data; name="1"

[object Object]
------WebKitFormBoundaryyhscsCwqLniB9NlA--

On the client-side I´m using 'apollo-upload-client' as described on their page.

I can see in the debugger that the error occurs in this function: (graphene_file_upload/utils.py)

def place_files_in_operations(operations, files_map, files):
    """Replaces None placeholders in operations with file objects in the files
    dictionary, by following the files_map logic as specified within the 'map'
    request parameter in the multipart request spec"""
    path_to_key_iter = (
        (value.split('.'), key)
        for (key, values) in iteritems(files_map)
        for value in values
    )
    # Since add_files_to_operations returns a new dict/list, first define
    # output to be operations itself
    output = operations
    for path, key in path_to_key_iter:
        file_obj = files[key]
        output = add_file_to_operations(output, file_obj, path)
    return output

-> file_obj = files[key]

the files array is empty.

Do you have an idea what I´m doing wrong?

@marlonpatrick
Copy link

Hey @fabull86 can you solve that error?

I'm evaluating this library. I wanted to know if it is stable considering that my application will use a lot of image uploads.

@luckyy199213
Copy link

The same problem

@felixmeziere
Copy link

same problem

@avaltat
Copy link

avaltat commented Oct 4, 2021

same problem

@felixmeziere
Copy link

Hey here, any intention to merge the PR to solve this problem?

@Delvio
Copy link

Delvio commented Nov 21, 2021

any workarounds for this issue?

@delegacy
Copy link

Same here. When would #66 be released?

@rukna123
Copy link

Yes guys, I'm on v1.3.0, and it's still throwing same error. When would #66 be released? @delegacy did you find any other way to get around this?

@Apro2011
Copy link

def place_files_in_operations(operations, files_map, files):
    """Replaces None placeholders in operations with file objects in the files
    dictionary, by following the files_map logic as specified within the 'map'
    request parameter in the multipart request spec"""
    path_to_key_iter = (
        (value.split('.'), key)
        for (key, values) in iteritems(files_map)
        for value in values
    )
    # Since add_files_to_operations returns a new dict/list, first define
    # output to be operations itself
    output = operations
    for path, key in path_to_key_iter:
        file_obj = files.get(key, None)
        output = add_file_to_operations(output, file_obj, path)
    return output

This solves the problem for me.

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

No branches or pull requests

9 participants