我正在尝试从用户输入的 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, os
from urllib.parse import urlparse
from shutil import copyfile
dirs = []
PORT = 8000
URIextra = ""
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 = True
os.chdir(os.getcwd() + "/web")
httpd = MyTCPServer(('localhost', PORT), CustomHandler)
httpd.allow_reuse_address = True
print("Serving at port", PORT)
httpd.serve_forever()
翻翻过去那场雪
呼啦一阵风
三国纷争
随时随地看视频慕课网APP
相关分类