我正在使用聊天网络应用。在聊天应用程序中,用户将创建一个他的帐户,然后服务器将执行以下过程(所有过程将在我的整个应用程序中使用 post 请求完成):-
服务器的代码是:-
elif 'signup%20name?=' and "%20pwd?=" in self.path:
users = open("users.txt", 'a+')
usr = (self.path).replace("/signinupsignup%20name?=", '')
usrpw = usr.replace("%20pwd?=", "<[-----=-----]>")
usrpwd = usrpw + '\n'
users.write(usrpwd)
users.close()
filenam = usrpw.replace('<[-----=-----]>', '')
filename = '/userhome/' + filenam + '.html'
htmlfile = open(filename, 'w')
htmlfile.write(r'<!DOCTYPE html>\n<html lang="en">\n<head>\nmeta charset="UTF-8">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n<title>User Home</title>\n<style>\n#navbar\n{\nbackground-color: purple;\ncolor: white;\ntext-align: center;\nposition: relative;\n}\n#chats a:hover\n{\ncolor: white;\nbackground-color: black;\n}\n</style>\n</head>\n<body>\n<div id="navbar">\n<div id="welcome">\n<h1>Cobra Chat-Room</h1>\n</div>\n</div>\n<div id="chats">\n<!-- chats of the user -->\n<a href="#">Group 1</a><br>\<noscript></noscript>\n</body>\n</html>\n')
self.path = '/success.html'
但是当我运行文件时出现以下错误:-
Exception occurred during processing of request from ('127.0.0.1', 41192)
Traceback (most recent call last):
File "/usr/lib/python3.9/socketserver.py", line 316, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python3.9/socketserver.py", line 347, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python3.9/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.9/socketserver.py", line 720, in __init__
self.handle()
File "/usr/lib/python3.9/http/server.py", line 427, in handle
self.handle_one_request()
File "/usr/lib/python3.9/http/server.py", line 415, in handle_one_request
method()
File "/home/kali/Desktop/SignUp/server.py", line 16, in do_GET
htmlfile = open(filename, 'w')
FileNotFoundError: [Errno 2] No such file or directory: '/userhome/ssss.html'
----------------------------------------
html 主页的文件名将是 <username><password>
,没有任何空格。它将存储在名为“userhome”的目录中
(操作系统 => Kali Linux;Pyhton 3.9 版)
答案 0 :(得分:0)
可能是你给的ip地址不对
或者检查服务器是否有静态ip
如果不是,它可能会改变