Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python socketserver正在从网页打开文件_Python_Sockets - Fatal编程技术网

python socketserver正在从网页打开文件

python socketserver正在从网页打开文件,python,sockets,Python,Sockets,我正在尝试制作一个在本地机器上运行的小型服务器,该服务器将从网页获取请求并在openoffice中打开一个文件。到目前为止,这种方法是有效的。然而,有时请求不会立即通过。当这种情况发生时,我会等待至少5秒钟,然后尝试再点击几次,然后所有的请求都同时进入。我真的希望这是可靠的。我有没有遗漏什么可以阻止这一切的发生?任何帮助都将不胜感激。我也知道我做事的方式可能不是最安全的。我正在努力使它的功能,然后将努力使它更安全 import SocketServer import subprocess imp

我正在尝试制作一个在本地机器上运行的小型服务器,该服务器将从网页获取请求并在openoffice中打开一个文件。到目前为止,这种方法是有效的。然而,有时请求不会立即通过。当这种情况发生时,我会等待至少5秒钟,然后尝试再点击几次,然后所有的请求都同时进入。我真的希望这是可靠的。我有没有遗漏什么可以阻止这一切的发生?任何帮助都将不胜感激。我也知道我做事的方式可能不是最安全的。我正在努力使它的功能,然后将努力使它更安全

import SocketServer
import subprocess
import time


class MyTCPHandler(SocketServer.StreamRequestHandler):
    def handle(self):
        # self.request is the TCP socket connected to the client
        self.data = self.rfile.readline().strip()
        print self.data

        try:
            if self.data != '':
                st = self.data.split('\n', 1)[0]
                #print st
                st = st.split(' ')[1]
                print st
                if ".odt" in st:
                    p = subprocess.Popen('C:\openoffice\program\swriter.exe "'+st[1:]+'"')
                    time.sleep(1)
                    p.terminate()
        except Exception as err:
            print err
        # just send back the same data, but upper-cased
        self.wfile.write(self.data.upper())

PORT = 8081
httpd = SocketServer.TCPServer(("", PORT), MyTCPHandler)
print "serving at port", PORT
httpd.serve_forever()