SystemRage / py-kms

KMS Server Emulator written in Python
The Unlicense
2.04k stars 618 forks source link

Running on Windows Server 2012 R2 #58

Closed aeyrnsun closed 3 years ago

aeyrnsun commented 4 years ago

I have the following scenario:

VM under VMWARE - Windows Server 2012 R2 - latest updates Python 2.7.17(64-bit) Python 2.7 pywin32-227 tzlocal-2.0.0-py2.py3-none-any.whl Source files in C:\PythonScipts\py-kms-master\py-kms

When I start the pykms_Server.py the following occurs:

C:\PythonScripts\py-kms-master\py-kms>python pykms_Server.py Exception in thread Thread-Srv: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner self.run() File "pykms_Server.py", line 150, in run self.server.pykms_serve() File "pykms_Server.py", line 81, in pykms_serve ready = selector.select(timeout) File "C:\PythonScripts\py-kms-master\py-kms\pykms_Selectors.py", line 327, in select self._writers, timeout) File "C:\PythonScripts\py-kms-master\py-kms\pykms_Selectors.py", line 128, in _syscall_wrapper raise SelectorError(errcode) SelectorError:

Any suggestions?

PS

I additionally duplicated this setup on a Server 2019 Standard Edition (running as a VM) and exactly the same result.

aeyrnsun commented 4 years ago

I have tried this also on a Windows 10 PRO running Python 3.8.2 with this...

Exception in thread Thread-Srv: Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\threading.py", line 932, in _bootstrap_inner self.run() File ".\pykms_Server.py", line 150, in run self.server.pykms_serve() File ".\pykms_Server.py", line 81, in pykmsserve ready = selector.select(timeout) File "C:\Program Files (x86)\Python38-32\lib\selectors.py", line 323, in select r, w, = self._select(self._readers, self._writers, [], timeout) File "C:\Program Files (x86)\Python38-32\lib\selectors.py", line 314, in _select r, w, x = select.select(r, w, w, timeout) OSError: [WinError 10038] An operation was attempted on something that is not a socket

simonmicro commented 4 years ago

I have tried this also on a Windows 10 PRO running Python 3.8.2 with this...

Exception in thread Thread-Srv: Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\threading.py", line 932, in _bootstrap_inner self.run() File ".\pykms_Server.py", line 150, in run self.server.pykms_serve() File ".\pykms_Server.py", line 81, in pykmsserve ready = selector.select(timeout) File "C:\Program Files (x86)\Python38-32\lib\selectors.py", line 323, in select r, w, = self._select(self._readers, self._writers, [], timeout) File "C:\Program Files (x86)\Python38-32\lib\selectors.py", line 314, in _select r, w, x = select.select(r, w, w, timeout) OSError: [WinError 10038] An operation was attempted on something that is not a socket

This is only a guess, but what other Software is running while you attempt this? My guess is, that python looses the socket context, maybe caused by a firewall or an anti-virus software. Please try disable all of them. If that still fails, I'll lool further into that.

05u commented 4 years ago

我也在具有此功能的运行Python 3.8.2的Windows 10 PRO上尝试过此操作... 线程Thread-Srv中的异常: 追溯(最近一次调用): 文件“ C:\ Program Files(x86)\ Python38-32 \ lib \ threading.py”,第932行,位于_bootstrap_inner self.run() 文件中。 \ pykms_Server.py”,第150行,运行 self.server.pykms_serve() 文件“。\ pykms_Server.py”,第81行,pykmsserve ready = selector.select(timeout) 文件“ C:\ Program Files(x86)” \ Python38-32 \ lib \ selectors.py“,第323行,在选择 r,w, = self._select(self._readers,self._writers,[],超时)中, 文件“ C:\ Program Files(x86) \ Python38-32 \ lib \ selectors.py“,第314行,在_select r,w,x = select.select(r,w,w,timeout) OSError中:[WinError 10038]尝试对非套接字的对象进行操作

这只是一个猜测,但是尝试执行此操作时还会运行什么其他软件?我的猜测是,python会松开套接字上下文,这可能是由防火墙或防病毒软件引起的。请尝试禁用所有这些。如果仍然失败,我将进一步讲解。

I have tried this also on a Windows 10 PRO running Python 3.8.2 with this... Exception in thread Thread-Srv: Traceback (most recent call last): File "C:\Program Files (x86)\Python38-32\lib\threading.py", line 932, in _bootstrap_inner self.run() File ".\pykms_Server.py", line 150, in run self.server.pykms_serve() File ".\pykms_Server.py", line 81, in pykmsserve ready = selector.select(timeout) File "C:\Program Files (x86)\Python38-32\lib\selectors.py", line 323, in select r, w, = self._select(self._readers, self._writers, [], timeout) File "C:\Program Files (x86)\Python38-32\lib\selectors.py", line 314, in _select r, w, x = select.select(r, w, w, timeout) OSError: [WinError 10038] An operation was attempted on something that is not a socket

This is only a guess, but what other Software is running while you attempt this? My guess is, that python looses the socket context, maybe caused by a firewall or an anti-virus software. Please try disable all of them. If that still fails, I'll lool further into that.

Hello, I have the same mistake. I tried to solve it but failed.

The computer system I run on the server is windows 10. There is no security software and the firewall is closed.

aeyrnsun commented 4 years ago

I have also tries this on HYPER-V vm's running on Server 2019 Standard, Server 2012 R2 Standard and Server 2016 Standard. All VM's very running with no anti virus or security software - out of the box so to speak! All failed to run

ldti commented 4 years ago

Same here. Used to work find on one of the older releases of py-kms. this is happening on a container , based on server 1809.

SystemRage commented 4 years ago

By now i can't debug anymore versus Windows errors because my Win test Pc is died. But i think the problem is that i used os.pipe() with Selectors / select() and stupid Windows only works for sockets. (https://docs.python.org/3/library/select.html) A quick and dirty fix is to comment (in pykms_Server.py) all references to self.r_service, self.w_service like this:

class KeyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
        daemon_threads = True
        allow_reuse_address = True

        def __init__(self, server_address, RequestHandlerClass):
                socketserver.TCPServer.__init__(self, server_address, RequestHandlerClass)
                self.__shutdown_request = False
                #self.r_service, self.w_service = os.pipe() #Comment here

                if hasattr(selectors, 'PollSelector'):
                        self._ServerSelector = selectors.PollSelector
                else:
                        self._ServerSelector = selectors.SelectSelector

        def pykms_serve(self):
                """ Mixing of socketserver serve_forever() and handle_request() functions,
                    without elements blocking tkinter.
                    Handle one request at a time, possibly blocking.
                    Respects self.timeout.
                """
                # Support people who used socket.settimeout() to escape
                # pykms_serve() before self.timeout was available.
                timeout = self.socket.gettimeout()
                if timeout is None:
                        timeout = self.timeout
                elif self.timeout is not None:
                        timeout = min(timeout, self.timeout)
                if timeout is not None:
                        deadline = time() + timeout

                try:
                        # Wait until a request arrives or the timeout expires.
                        with self._ServerSelector() as selector:
                                selector.register(fileobj = self, events = selectors.EVENT_READ)
                                # self-pipe trick.
                                #selector.register(fileobj = self.r_service, events = selectors.EVENT_READ) #Comment here

                                while not self.__shutdown_request:
                                        ready = selector.select(timeout)
                                        if self.__shutdown_request:
                                                break

                                        if ready == []:
                                                if timeout is not None:
                                                        timeout = deadline - time()
                                                        if timeout < 0:
                                                                return self.handle_timeout()
                                        else:
                                                for key, mask in ready:
                                                        if key.fileobj is self:
                                                                self._handle_request_noblock()
                                                        #elif key.fileobj is self.r_service:  ##Comment this block.
                                                                # only to clean buffer.
                                                                #msgkill = os.read(self.r_service, 8).decode('utf-8')
                                                                #sys.exit(0)
                finally:
                        self.__shutdown_request = False

in this way however py-kms Gui Exit button functionality is lost. A more appropriate fix (with a next update) is to create a socketpair() function working with python2 and Windows.

16486994 commented 3 years ago

As far as I know, can this thing be started on Linux and then activated on windows。What is the result of using it?