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

Content-Type in multipart/form-data POST data #356

Open
tobru opened this issue Feb 13, 2021 · 2 comments
Open

Content-Type in multipart/form-data POST data #356

tobru opened this issue Feb 13, 2021 · 2 comments

Comments

@tobru
Copy link

tobru commented Feb 13, 2021

In https://github.com/MechanicalSoup/MechanicalSoup/blob/master/mechanicalsoup/browser.py#L203 the 2-tuple of the files parameter ('filename', fileobj) is used.

I have a use case where I have to be explicit about the Content-Type in the multipart part of the POST request, otherwise the server doesn't accept the file. By directly using requests I could use the 3-tuple parameter ('filename', fileobj, 'content_type'), which I've tried and works.

How can I do that with MechanicalSoup StatefulBrowser?

@moy
Copy link
Collaborator

moy commented Feb 15, 2021

I don't think there's an easy way other than patching MechanicalSoup, but patches are welcome if it solves a problem.

I'm wondering how this content type can be computed. Just guessed from the local file content? Set by the programmer from the MechanicalSoup API (probably the best option to be realiable), e.g. by allowing browser["file-field"] = (filename, content-type)?

@tobru
Copy link
Author

tobru commented Feb 23, 2021

Just guessed from the local file content?

That would be one possibility, yes.

Set by the programmer from the MechanicalSoup API (probably the best option to be realiable), e.g. by allowing browser["file-field"] = (filename, content-type)

That would be perfectly fine and absolutely enough for my use-case. This could even be the preferred way over automagically detecting the file type as this could go wrong and then you're out of luck again. I'm a fan of being able to specify things explicitely.

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

2 participants