Ad

Cant Understand Request Response Json

- 1 answer

I am sending requests to discord but the json response is encoded. I dont know how to convert it to the json which is shown in

cookies = {
    '__dcfduid': '9cdb771aa91811ecbbb166a2644e1ebd',
    '__sdcfduid': '9cdb771aa91811ecbbb166a2644e1ebd4139917683b03f98166d7f12ed245c6b4eec20a521219fa14bc3dcad9fc83f17',
    '__cf_bm': 'XATJg9tmbXKxU0XYhhk_NEc7jJI3G9cezBLutkAPL14-1647867777-0-AVUnjtyleUf5uH4NZKnrirKJ67tGnkxs3rdmrUmPM7jxGtiu7AV0DEfzOThZyTXG+6WwhYAvb4vecRMRQLixl7sX5hKh05wldjuEukidOaruFgJ0EFkBwt9f3/fv678s1g==',
    'locale': 'en-US',
}

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0',
    'Accept': '*/*',
    'Accept-Language': 'en-US,en;q=0.5',
    'Accept-Encoding': 'gzip, deflate, br',
    'Content-Type': 'application/json',
    'Authorization': 'Token here',
    'X-Super-Properties': 'eyJvcyI6IldpbmRvd3MiLCJicm93c2VyIjoiRmlyZWZveCIsImRldmljZSI6IiIsInN5c3RlbV9sb2NhbGUiOiJlbi1VUyIsImJyb3dzZXJfdXNlcl9hZ2VudCI6Ik1vemlsbGEvNS4wIChXaW5kb3dzIE5UIDEwLjA7IFdpbjY0OyB4NjQ7IHJ2Ojk4LjApIEdlY2tvLzIwMTAwMTAxIEZpcmVmb3gvOTguMCIsImJyb3dzZXJfdmVyc2lvbiI6Ijk4LjAiLCJvc192ZXJzaW9uIjoiMTAiLCJyZWZlcnJlciI6IiIsInJlZmVycmluZ19kb21haW4iOiIiLCJyZWZlcnJlcl9jdXJyZW50IjoiIiwicmVmZXJyaW5nX2RvbWFpbl9jdXJyZW50IjoiIiwicmVsZWFzZV9jaGFubmVsIjoic3RhYmxlIiwiY2xpZW50X2J1aWxkX251bWJlciI6MTE5ODgwLCJjbGllbnRfZXZlbnRfc291cmNlIjpudWxsfQ==',
    'X-Discord-Locale': 'en-US',
    'X-Debug-Options': 'bugReporterEnabled',
    'Origin': 'https://discord.com',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Referer': 'https://discord.com/channels/@me/948159391838904380',
    # Requests sorts cookies= alphabetically
    # 'Cookie': '__dcfduid=9cdb771aa91811ecbbb166a2644e1ebd; __sdcfduid=9cdb771aa91811ecbbb166a2644e1ebd4139917683b03f98166d7f12ed245c6b4eec20a521219fa14bc3dcad9fc83f17; __cf_bm=XATJg9tmbXKxU0XYhhk_NEc7jJI3G9cezBLutkAPL14-1647867777-0-AVUnjtyleUf5uH4NZKnrirKJ67tGnkxs3rdmrUmPM7jxGtiu7AV0DEfzOThZyTXG+6WwhYAvb4vecRMRQLixl7sX5hKh05wldjuEukidOaruFgJ0EFkBwt9f3/fv678s1g==; locale=en-US',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'Pragma': 'no-cache',
    'Cache-Control': 'no-cache',
    # Requests doesn't support trailers
    # 'TE': 'trailers',
}

data = {
    'content':'hello',
    'nonce':955456750633353216,
    'tts':False}

response = requests.post('https://discord.com/api/v9/channels/948159391838904380/messages', headers=headers, cookies=cookies, json=data)

print(response.status_code)
print(response.content)

The response is

b'\x03\xfe\x00\x00dS\x97\xd3\xaa\xd3\xfa$\x03.s7vc}\x1bR\xf2D\xeb\x8e\[email protected]\xda\xfa!\xe2\x96\x05Q\x8b\xc20\r0\x0b(\xf8!\x080\x93\x0b\xa6\xa7\xfa\
xf6\xecd\x08\xbd;\xf1\xcf\x03\xdb\x8a\x1909\x17bJ\xde\xc4\x98\x8c\xf3Q\x13.\x01\x8f\xb7\x991\x03-\x01G\xbf\xed3\xe0?\x0f\xc3dq\t\xc8\xdd\xa8\xbe
\xe30\xd6ze\xb5O\x9a\xbcsQ\x90\xe7\xd0fH\xc7\xd9`}H\xc6{\x1d\x83#-\xf2\xe9\xc0{)#c\x06\xdc\x16i[\x7f8\x97c\xb9\x90\xd30,\x01k{h\xf6\xed\xd8J9\x8
6]\xa1I1\xe1\x12pyzM\xf3\xbd\x1d\xca\xdf\x013\xd0k\t\xd8\xfc\xc3\x013\xbc\x7f.\x01y\xfc\xe5\xaa\xa1\xd9j\xc5\x13\xbe\xf7\xd3\xc0\x06\xe5\xdc\x8a
p\xc5\x0c\xdb2\x1c\xf8e\xb6D}?\t\x9b\xdd1\x1bi^\xb6#\x1f\x8ee\x9c1\x03j\xd2zEf\xa5\xf5\x9bRY\xc7Ln\xad\x14\x11\xd1\x82(S\xc7g\\\xdb#\xd7o_[;\xd5
f\xc0\x18\xc6y\x92\xebe\x92\x86\x81\x14\xa2w\xd6yR\xc1\x07R\x16(\xfcI>bi\xb8~\x13X\x12\xcc \xa7ax\x19\x03'

Does any one know how to get the json as shown in developers tool. I have never seen this type of response and know nothing about it. I want to know this for educational purpose. As message being sent without knowing the response.

Ad

Answer

You should use response.json() to get it as a JSON.

response.content returns a binary representation.

Ad
source: stackoverflow.com
Ad