Urlencoded sending a JSON string

I have an API that has been set up on the server side and the unit side, I have the below code in python to communicate with the API. I am now writing this for the Arduino IDE.

This code successfully communicates with the API to get the token.

How is this code sending a JSON string ‘auth_info’ while the header reads x-www-form-urlencoded.

Even a half explanation of the following would be really appreciated.

PYTHON CODE STARTS

def get_user_auth_token():
    global token

    purl = host+'/api/oauth/token'
    head = {'Content-Type' : 'application/x-www-form-urlencoded'}    
    auth_info = {'client_id' : "unit:"+api_params.id,
                'grant_type' : 'client_credentials',
                'client_secret' : api_params.secret,
                'scope' : 'unit',
                }  

    # print(purl)
    # print(auth_info)
    # print(head)

   
    r = requests.post(purl, auth_info, head)
 
    response=json.loads(r.text)
    token = response['access_token']

PYTHON CODE ENDS

Why do you think it’s sending JSON? It should be form encoded.

Here I run something very similar on my machine:

>>> import requests
>>> head = {'Content-Type' : 'application/x-www-form-urlencoded'}
>>> auth_info = {'client_id': 'unit:5555', 'scope': 'unit', 'client_secret': 'shh.. secret!'}
>>> r = requests.post('http://localhost:8888/', auth_info, head)

And I just receive it in a terminal running nc -l 8888

$ nc -l 8888
POST / HTTP/1.1
Host: localhost:8888
User-Agent: python-requests/2.26.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Content-Length: 62
Content-Type: application/x-www-form-urlencoded

client_id=unit%3A5555&scope=unit&client_secret=shh..+secret%21

I don’t see any JSON being sent. This is form encoding as expected from the post() default.