Issue
I have an SSH connection from a Windows machine to another, and then trying to do a poetry install.
My problem is: I get this error when executing poetry install through ssh:
[WinError 1312] A specified logon session does not exist. It may already have been terminated.
This command works perfectly when I execute it locally on the target machine, but fails when connecting through ssh.
How can I get rid/fix the [WinError 1312]?
I saw another user that posted the same question recently, but removed it.
I've seen some clues regarding the MachineKeys, but have really no idea on how to proceed. Any suggestion will be highly appreciated.
Python: 3.10.8
Poetry: 1.2.1
Installing dependencies from lock file
Package operations: 5 installs, 0 updates, 0 removals
• Installing install-requires (0.3.0)
OSError
[WinError 1312] A specified logon session does not exist. It may already have been terminated.
at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\win32ctypes\core\ctypes\_util.py:53 in check_zero
49│
50│ def check_zero_factory(function_name=None):
51│ def check_zero(result, function, arguments, *args):
52│ if result == 0:
→ 53│ raise make_error(function, function_name)
54│ return result
55│ return check_zero
56│
57│
The following error occurred when trying to handle this error:
error
(1312, 'CredRead', 'A specified logon session does not exist. It may already have been terminated.')
at ~\AppData\Roaming\pypoetry\venv\lib\site-packages\win32ctypes\pywin32\pywintypes.py:37 in pywin32error
33│ def pywin32error():
34│ try:
35│ yield
36│ except WindowsError as exception:
→ 37│ raise error(exception.winerror, exception.function, exception.strerror)
38│
Solution
Based on similarities in the stack traces and your description, my guess is that you're facing the same bug from #1892 and #1917, where Poetry tries to use your keyring to access/publish modules, and hence fails when these credentials are invalid.
But it appears that poetry tries to access the keyring even for install operations.
One of the solutions proposed was to uninstall the keyring
package remotely:
For me, I worked around the problem by pip uninstalling the 'keyring' package from that virt env.
Another solution is to export the environment variable PYTHON_KEYRING_BACKEND
. Here's an example of how you can do that on Windows cmd:
SET PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
or Windows powershell:
$env:PYTHON_KEYRING_BACKEND="keyring.backends.null.Keyring"
or Linux shell:
export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring
Unfortunately, it appears that issue #1917 is still open and unresolved, so this is the best workaround that you can find to fix the issue for now.
Answered By - Xiddoc Answer Checked By - Mildred Charles (WPSolving Admin)