[Python] How to always get the status of the robot when using POST request and not make the...

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I created a Windows application in Python and the Kivy framework. The main feature of the app is to post the request on the server in API through a button. The server will send the task to a robot and will respond to my app in JSON format. Depending on the status of the robot, the server will give the data following it, and I will give the feedback to the user in color.

    For example, the server response "taskStatus":"4"

    I will display the green color, and if the server response number is "6" I will display the orange.

    I try using the "thread" and "schedule" modules to test it. But it still makes the app crash. You can see my example code

    from threading import Thread

    def post_device_status_background():
    api_url_get = "http://*.*.*.*:7000/ics/out/task/getTaskOrderStatus"
    data = {
    "areaId": "1",
    "deviceType": "0",
    "deviceCode": "khang0000"
    }
    try:
    response = requests.post(api_url_get, json=data)
    print("Device status:", response.json())
    except Exception as e:
    print(f"Error: {e}")

    def post_device_status(self, dt):
    Thread(target=post_device_status_background).start()

    Clock.schedule_interval(post_device_status, 10)


    The main point of my question is how to always get the status of the robot after clicking the button and not make the app crash? Do you have any advice?

    Continue reading...

Compartilhe esta Página