'[Python]Query http request

How to query id from the url? I want to get id from request so I tried this but it doesn't work.

My request url:http://localhost:8888/api/genshin?id=119480035 then it gives me 404.I expect it can query the id instead of 404

def do_GET(self):
        if self.path == "/api/genshin":
            # request url example: /api/genshin?id=119480035
            id = self.path.split("=")[1]
            data = asyncio.run(main(id))
            self.send_response(200)
            self.send_header('Content-type', 'application/json')
            self.end_headers()
            self.wfile.write(bytes(json.dumps(data), "utf-8"))
        else:
            self.send_response(404)
            self.send_header('Content-type', 'text/html')
            self.end_headers()
            self.wfile.write(bytes("<h1>404 Not Found</h1>", "utf-8"))


Solution 1:[1]

?id=119480035 is query parameter, you need to pass it when making the request, and depends on it's a GET or POST request, it's different to pass.

For example: Python Request Post with param data

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1