question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

POST request fails when both data and files are provided

See original GitHub issue

When making a POST request with both data and files keyword arguments the request fails with:

$ pybot test1.txt                                                                
==============================================================================
Test1                                                                         
==============================================================================
Test One                                                              | FAIL |
ValueError: Data must not be a string.
------------------------------------------------------------------------------
Test1                                                                 | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================

Requests Python library makes a check against data (when using files) in requests/models.py in function _encode_files:

if (not files):
    raise ValueError("Files must be provided.")
elif isinstance(data, basestring):
    raise ValueError("Data must not be a string.")

Here is test case to reproduce the error:

*Settings*

Library  RequestsLibrary
Library  OperatingSystem

*Test Case*
Test One
     Create Session  Foo  http://localhost
     ${data}=  Create Dictionary  foo=bar
     Create File  foobar  content=foobar
     ${files}=  Evaluate  open('foobar')
     Post Request  Foo  /foo  data=${data}  files=${files}

I’m using the following library versions (from pip list):

  • requests (2.11.1)
  • robotframework (3.0)
  • robotframework-requests (0.4.5)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
vkosuricommented, Oct 5, 2016

@volinthius thank you all your observations, I am little busy with other tasks, Pull requests are much appreciated!!

0reactions
AntonioBusillocommented, Jun 19, 2018

Ok it seems to work. Maybe, in the first test, I just messed up something. Thank you for your help 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST request fails when sending too much data
The file data is stored as a string. var fd = new FormData(); fd.append('fileString', file.attachmentString); fd.append( ...
Read more >
Error when POST file multipart/form-data · Issue #505 - GitHub
Hi, I got an error every time when trying to POST data to the API. Request: changeUserAvatar(authParam, file) { let formData = new...
Read more >
Solved: Post File via HTTP - Power Platform Community
Solved: I can't get this to work in flow. I get bad request. Below is the 400 status code and the header and...
Read more >
$_FILES - Manual - PHP
If $_FILES is empty, even when uploading, try adding enctype="multipart/form-data" to the form tag and make sure you have file uploads turned on....
Read more >
Upload file data | Google Drive
Note: In the Drive API documentation, media refers to all available files with MIME ... Create a POST request to the method's /upload...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found