How to write all the data received by POST to a file?

I have a Python script on a webserver that receives POST data from another webpage. For troubleshooting I’m trying to write the raw POST data to a text file. In PHP this does it:

file_put_contents("test.txt", file_get_contents('php://input'));

I don’t imagine anyone has any ideas for doing the same in Python?

That will depend on the library you’re using to implement the webserver.

Sorry should have said. An apache webserver in a shared hosting environment.