how to post multiple value with same key in python requests?

Question:, data={'interests':'football','interests':'basketball'})

I tried this, but it is not working. How would I post football and basketball in the interests field?

Asked By: Jasonyi



Dictionary keys must be unique, you can’t repeat them. You’d use a sequence of key-value tuples instead, and pass this to data:, data=[('interests', 'football'), ('interests', 'basketball')])

Alternatively, make the values of the data dictionary lists; each value in the list is used as a separate parameter entry:, data={'interests': ['football', 'basketball']})

Demo POST to

>>> import requests
>>> url = ''
>>> r =, data=[('interests', 'football'), ('interests', 'basketball')])
>>> r.request.body
>>> r.json()['form']
{u'interests': [u'football', u'basketball']}
>>> r =, data={'interests': ['football', 'basketball']})
>>> r.request.body
>>> r.json()['form']
{u'interests': [u'football', u'basketball']}
Answered By: Martijn Pieters

It is possible to use urllib3._collections.HTTPHeaderDict as a dictionary that has multiple values under a key:

from urllib3._collections import HTTPHeaderDict
data = HTTPHeaderDict()
data.add('interests', 'football')
data.add('interests', 'basketball'), data=data)
Answered By: Sjoerd

Quoting from the docs directly:

The data argument can also have multiple values for each key. This can
be done by making data either a list of tuples or a dictionary with
lists as values. This is particularly useful when the form has
multiple elements that use the same key:

>>> payload_tuples = [('key1', 'value1'), ('key1', 'value2')]
>>> r1 ='', data=payload_tuples)
>>> payload_dict = {'key1': ['value1', 'value2']}
>>> r2 ='', data=payload_dict)
>>> print(r1.text)
  "form": {
    "key1": [
>>> r1.text == r2.text
Answered By: Mooncrater
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.