How do I send this post data as JSON with Python request?

43 Views Asked by At

I try this post data send python with request json

{"APIRequests":[{"ApplicationId":"com.xsd.v1.1","Name":"JACK","SurName":"DANIEL","Verb":"Authenticate"}]}

I am trying to send like this

    oturum = requests.Session()
    headers = {
        'Host': 'www.xsd.com',
        'Content-type': 'application/json',
        'User-Agent': 'okhttp/3.12.1'}

    datapost= {'APIRequests': {'ApplicationId': "com.xsd.v1.1", 'Name': JACK, 'SurName':DANIEL,'Verb':'Authenticate'}}

    req = oturum.post("https://www.xsd.com/api/", headers=headers, json=datapost)

    print(req.json())
{'ServerTime': 'Tue, 08 Nov 2022 10:12:28 -0600', 'APIVersion': '11.2', 'Status': 'Error', 'ErrorCode': 6, 'ErrorMessage': 'The API requests are invalid.'}
    print(req.request.body)
b'{"APIRequests": {"ApplicationId": "com.xsd.v1.1", "Name": "JACK", "SurName": "DANIEL", "Verb": "Authenticate"}}'

But it's not right not working. Help please. Thank you

And why there is "b" in request body? is it normal?

0

There are 0 best solutions below