From 6f300930010bb1332f66fd822e7a4fcfb3ce43bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=B3=E5=85=89=E5=B0=91=E5=B9=B4?= <849317537@qq.com> Date: Thu, 12 Sep 2024 09:40:37 +0000 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/service/client.py | 7 +++++++ test/service/server.py | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/service/client.py b/test/service/client.py index 1c2ceb3..55fc202 100644 --- a/test/service/client.py +++ b/test/service/client.py @@ -2,9 +2,16 @@ code = """ import time import os +import http.client + print("hello world") print(os.environ) +print(os.listdir()) + +conn = http.client.HTTPConnection("www.baidu.com") +conn.request("GET", "/") +print(conn.getresponse().read().decode('utf-8')) """ if __name__ == "__main__": diff --git a/test/service/server.py b/test/service/server.py index e22532e..9c8cf33 100644 --- a/test/service/server.py +++ b/test/service/server.py @@ -9,12 +9,15 @@ app = Flask(__name__) USER_NAME = "ubuntu" ROCKER_PATH = f"/home/{USER_NAME}/rocker/target/debug/rocker" + @app.route("/", methods=["POST"]) -def hello_world(): +def main(): + code = request.json.get("code", "") + _id = str(random.randint(8000_0000, 9000_0000)) user_path = f"/tmp/{_id}" os.mkdir(user_path) - code = request.json.get("code", "") + with open(f"{user_path}/main.py", "w") as f: f.write(code)