0

Below is my code snippet in which i am trying to read the data from request body.

from fastapi import Request

async def my_action(request: Request):
    data = await request.body()
    print(data) #prints the data as mentioned below in o/p
    print(data.decode("utf-8")) #prints data in the same way as mentioned in o/p
    print(data.decode())  #prints data in the same way as mentioned in o/p

i/p : "process query=my_event my_User=king Prop_A="Prop Val" Prop_B=Val_B other=1 Minutes"

o/p : b'process+query%3Dmy_event+my_User%3Dking+Prop_A%3D%22Prop+Val%22+Prop_B%3DVal_B+other%3D1+Minutes'

Problem here is, when I try to decode the byte stream, it still prints the same data as in the byte format. So how can I decode it to get it in the same format as in i/p ?

Thanks in advance!

Parashuram
  • 1,498
  • 2
  • 16
  • 36
  • @user12932966 : yes it was exactly what i was looking for and that has worked. Thanks a lot!! Will be closing this as well. – Parashuram May 27 '21 at 15:00
  • @lenz: yes, that was what i was looking for. Its the same as shared by user12932966 above. – Parashuram May 27 '21 at 16:54
  • Sorry for the noise – that comment is automatically created when close-voting. As the post author, you're probably able to speed up closing (or deletion, if you prefer). – lenz May 27 '21 at 17:43

0 Answers0