3

I am trying to use request to PUT some data as such,

r = requests.put(
        url,
        data={'tiles': []},
        headers={'x-auth-token': token}
    )

However, tiles is not sent if it is just an empty list. tiles only appears when the data is not empty. I checked this with http://httpbin.org/put also.

Does anyone have any ideas how to put empty data?

1
  • You mean 'tiles': []? Why are you setting it to an empty list? A list is seen as 0 or more values for the parameter, so 'tiles': ['foo', 'bar'] becomes tiles=foo and tiles=bar. Commented Aug 4, 2017 at 17:04

1 Answer 1

4

Naturally I figured it out immediately after asking. I wanted to use json inplace of data.

r = requests.put(
        url,
        json={'tiles': []},
        headers={'x-auth-token': token}
    )
Sign up to request clarification or add additional context in comments.

2 Comments

That's a very different datatype!
Is it just me, or is this undocumented for requests.put()? I couldn't find anywhere in the documentation that you can pass a json= keyword argument in place of data=. This helped though, so thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.