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

aiohttp.MultipartWriter.append() returns None #1798

Closed
paulannetts opened this issue Apr 7, 2017 · 10 comments
Closed

aiohttp.MultipartWriter.append() returns None #1798

paulannetts opened this issue Apr 7, 2017 · 10 comments
Assignees
Labels
Milestone

Comments

@paulannetts
Copy link

Long story short

Scenario is to send a multi-part message from test client containing a file with custom filename. Following the instructions from http://aiohttp.readthedocs.io/en/stable/multipart.html#sending-multipart-requests

It used to work in aiohttp 1.3.5, in aiohttp 2.0.6 it generates a None exception and the documentation doesn't mention any clear breaking change.

Expected behaviour

It should work as v1.3.5 or the documentation should be clearly updated to a working example.

Actual behaviour

The line mpwriter.append is now returning None, so the part.set_content_disposition is raising an exception.

Steps to reproduce

    with aiohttp.MultipartWriter('my_multi_part') as mpwriter:
        mpwriter.append_json({'key1': 'value1', 'key2': 'value2'})
        part = mpwriter.append(open(A_FILE_PATH))
        part.set_content_disposition('attachment', filename='my_custom_file.txt')

Your environment

Ubuntu 16.04, Python 3.5.2, pip install of aiohttp 2.0.6

@fafhrd91
Copy link
Member

fafhrd91 commented Apr 7, 2017

could you post full traceback

@paulannetts
Copy link
Author

paulannetts commented Apr 7, 2017

=================================== FAILURES ===================================
______________________________ test_upload_dummy _______________________________

    async def test_upload_dummy():
        A_FILE_PATH = str(os.path.dirname(os.path.realpath(__file__)) + '/data/test.txt')
        with aiohttp.MultipartWriter('my_multi_part') as mpwriter:
            mpwriter.append_json({'key1': 'value1', 'key2': 'value2'})
            part = mpwriter.append(open(A_FILE_PATH))
>           part.set_content_disposition('attachment', filename='my_custom_file.txt')
E           AttributeError: 'NoneType' object has no attribute 'set_content_disposition'

=========================== 1 failed in 0.12 seconds ===========================

That is the full traceback by the way, because append() returns None.

@fafhrd91 fafhrd91 added this to the 2.1 milestone Apr 8, 2017
@m-aciek
Copy link

m-aciek commented May 31, 2017

@fafhrd91 Did you find a workaround for your problem?

@asvetlov
Copy link
Member

@kxepal could you take a look?

@asvetlov asvetlov modified the milestones: 2.3.0, 2.1 Jun 26, 2017
@kxepal kxepal self-assigned this Jun 26, 2017
@fafhrd91
Copy link
Member

This is not a bug. This is documentation issue related to payloads

@kxepal
Copy link
Member

kxepal commented Jun 27, 2017

So, undocumented breaking change?

@paulannetts
Copy link
Author

paulannetts commented Sep 8, 2017

New way of doing this, using the new payload system.

 with aiohttp.MultipartWriter('my_multi_part') as mpwriter:
        mpwriter.append_json({'key1': 'value1', 'key2': 'value2'})
        payload = aiohttp.payload.TextIOPayload(open(A_FILE_PATH))
        payload.set_content_disposition('attachment', filename='my_custom_file.txt')
        mpwriter.append_payload(payload)

@asvetlov asvetlov modified the milestones: 2.3, 3.0 Oct 17, 2017
@asvetlov asvetlov modified the milestones: 3.0, 3.1 Feb 12, 2018
@asvetlov asvetlov modified the milestones: 3.1, 3.2 Mar 22, 2018
@roganov
Copy link
Contributor

roganov commented Apr 19, 2018

I believe this is fixed by #2759

@asvetlov
Copy link
Member

Yes, you are right

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants