How to get an answer from the server using json.



  • I'm sending a request to the server:

    data = {'user': i, 'text' : b}
    resp = requests.get('http://10.27.1.9:5000/newmessage', params=data)
    

    I want a server response in the console as:

    Nikneim: text (date)

    How do I do all this?



  • Server returns the list, so process it as a list:

    resp = ...
    for message in resp.json():
        print(f"{message['user']}: {message['text']} ({message['timestamp']})\n")
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2