close

[Solved] How to send an array using requests.post (Python)? “Value : Too many values to unpack”

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error How to send an array using requests.post (Python)? “Value : Too many values to unpack” in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How to send an array using requests.post (Python)? “Value : Too many values to unpack” Error Occurs?

Today I get the following error How to send an array using requests.post (Python)? “Value : Too many values to unpack” in python.

How To Solve send an array using requests.post (Python)? “Value : Too many values to unpack” Error ?

  1. How To Solve send an array using requests.post (Python)? “Value : Too many values to unpack” Error ?

    To Solve send an array using requests.post (Python)? “Value : Too many values to unpack” Error By using the json keyword argument the data is encoded to JSON for you, and the Content-Type header is set to application/json.

  2. How to send an array using requests.post (Python)? “Value : Too many values to unpack”

    To Solve send an array using requests.post (Python)? “Value : Too many values to unpack” Error By using the json keyword argument the data is encoded to JSON for you, and the Content-Type header is set to application/json.

Solution 1

You want to pass in JSON encoded data.

Remember — All post bodies must be JSON encoded data (no form data).

The requests library makes this trivially easy:

headers = {"W-Token": "Ilovemyboss"}
data = [
    {
        'url': '/rest/shifts',
        'params': {'user_id': 0, 'other_stuff': 'value'},
        'method': 'post',
    },
    {
        'url': '/rest/shifts',
        'params': {'user_id': 1,'other_stuff': 'value'},
        'method':'post',
    },
]
requests.post(url, json=data, headers=headers)

By using the json keyword argument the data is encoded to JSON for you, and the Content-Type header is set to application/json.

Solution 2

Well, It turns out that all I needed to do was add these headers:

headers = {'Content-Type': 'application/json', 'Accept':'application/json'}

and then call requests

requests.post(url,data=json.dumps(payload), headers=headers)

and now i’m good!

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read