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?

Shatnerz
  • 2,353
  • 3
  • 27
  • 43
  • 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`. – Martijn Pieters Aug 04 '17 at 17:04

1 Answers1

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}
    )
Shatnerz
  • 2,353
  • 3
  • 27
  • 43
  • That's a very different datatype! – Martijn Pieters Aug 04 '17 at 17:05
  • 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! – Engineero Dec 17 '18 at 22:51