我正在尝试从用户输入的 url 中提取查询字符串,该字符串将变成整数,因此http://127.0.0.1:8000/?1653。当我尝试这样做时,python 给了我错误,文件“C:\Users...\Documents\webserver\server.py”,第 26 行,在 do_GET int(URIextra) ValueError 中:int() 的无效文字,基数为 10:''我不知道我在这里做错了什么,任何帮助将不胜感激。import http.server, socketserver, osfrom urllib.parse import urlparsefrom shutil import copyfiledirs = []PORT = 8000URIextra = ""class CustomHandler(http.server.SimpleHTTPRequestHandler): def __init__(self, req, client_addr, server): http.server.SimpleHTTPRequestHandler.__init__(self, req, client_addr, server) def do_GET(self): o = urlparse(self.path) URIextra = str(o[4]) http.server.SimpleHTTPRequestHandler.do_GET(self) print(URIextra) dirs = os.listdir() f = open("index.txt", "w") f.write(os.listdir()) f.close() int(URIextra) copyfile(dirs[URIextra], "CurrentFile.mp3")class MyTCPServer(socketserver.ThreadingTCPServer): allow_reuse_address = Trueos.chdir(os.getcwd() + "/web")httpd = MyTCPServer(('localhost', PORT), CustomHandler)httpd.allow_reuse_address = Trueprint("Serving at port", PORT)httpd.serve_forever()
添加回答
举报
0/150
提交
取消