{"id":1003,"hash":"55ca69f0643096cc066cd216f68d1cbfcea063b01bef1bf9ac9a12e9b2d17fd2","pattern":"How to send an array using requests.post (Python)? &quot;Value Error: Too many values to unpack&quot;","full_message":"I'm trying to send an array(list) of requests to the WheniWork API using requests.post, and I keep getting one of two errors. When I send the list as a list, I get an unpacking error, and when I send it as a string, I get an error asking me to submit an array. I think it has something to do with how requests handles lists. Here are the examples:\n\nurl='https://api.wheniwork.com/2/batch'\nheaders={\"W-Token\": \"Ilovemyboss\"}\ndata=[{'url': '/rest/shifts', 'params': {'user_id': 0,'other_stuff':'value'}, 'method':'post',{'url': '/rest/shifts', 'params': {'user_id': 1,'other_stuff':'value'}, 'method':'post'}]\nr = requests.post(url, headers=headers,data=data)\nprint r.text\n\n# ValueError: too many values to unpack\n\nSimply wrapping the value for data in quotes:\n\nurl='https://api.wheniwork.com/2/batch'\nheaders={\"W-Token\": \"Ilovemyboss\"}\ndata=\"[]\" #removed the data here to emphasize that the only change is the quotes\nr = requests.post(url, headers=headers,data=data)\nprint r.text\n\n#{\"error\":\"Please include an array of requests to make.\",\"code\":5000}","ecosystem":"pypi","package_name":"python-requests","package_version":null,"solution":"You want to pass in JSON encoded data. See the API documentation:\n\n  Remember — All post bodies must be JSON encoded data (no form data).\n\nThe requests library makes this trivially easy:\n\nheaders = {\"W-Token\": \"Ilovemyboss\"}\ndata = [\n    {\n        'url': '/rest/shifts',\n        'params': {'user_id': 0, 'other_stuff': 'value'},\n        'method': 'post',\n    },\n    {\n        'url': '/rest/shifts',\n        'params': {'user_id': 1,'other_stuff': 'value'},\n        'method':'post',\n    },\n]\nrequests.post(url, json=data, headers=headers)\n\nBy using the json keyword argument the data is encoded to JSON for you, and the Content-Type header is set to application/json.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/31168819/how-to-send-an-array-using-requests-post-python-value-error-too-many-values","votes":91,"created_at":"2026-04-19T04:52:09.115829+00:00","updated_at":"2026-04-19T04:52:09.115829+00:00"}