-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Hello,
I'm stuck with the error in the title and tried a lot of things to get rid of it. I hope, I'm in the right place because cryptography is "only" used as dependency in another module (requests_ntlm2). When I run the code from powershell (python myscript.py) it runs fine. But when I use the same code to run it as a Windows service (pywin32) I get always the traceback shown later.
Environment:
- I run the powershell as the same user than is configured for the Windows service (it's an account in ActiveDirectory, no local account)
- Windows Server 2016 (german)
- Python 3.10.11
- All packages are globally installed with pip as administrator
I've uninstalled already cryptography and its dependencies but no change after reinstall (postinstall-script for pywin32 executed several times). I've compared environment-variables in both cases and found only minor differences (see screenshot). I've imported other modules without any problems (e. g. requests). I've also played around with different PYTHONPATH-variations, but I don't know where the DLL should be (the other modules seem to be found as seen in the Traceback). I also found Issue 7836 but it contains no hint, where else I could look.
Code which forces the error:
from requests_ntlm2 import (
HttpNtlmAuth,
HttpNtlmAdapter,
NtlmCompatibility
)
Traceback:
Python could not import the service's module
Traceback (most recent call last):
File "C:\OutputFactory\Skripte\OutputFactory.Infinica.Error_Monitoring_Service\pyWinService.py", line 10, in <module>
import ServiceWorkerImpl
File "C:\OutputFactory\Skripte\OutputFactory.Infinica.Error_Monitoring_Service\ServiceWorkerImpl.py", line 7, in <module>
from requests_ntlm2 import (
File "C:\Program Files\Python310\lib\site-packages\requests_ntlm2\__init__.py", line 1, in <module>
from .adapters import HttpNtlmAdapter, HttpProxyAdapter
File "C:\Program Files\Python310\lib\site-packages\requests_ntlm2\adapters.py", line 8, in <module>
from .connection import DEFAULT_HTTP_VERSION
File "C:\Program Files\Python310\lib\site-packages\requests_ntlm2\connection.py", line 12, in <module>
from .core import NtlmCompatibility, get_ntlm_credentials, noop
File "C:\Program Files\Python310\lib\site-packages\requests_ntlm2\core.py", line 8, in <module>
from cryptography import x509
File "C:\Program Files\Python310\lib\site-packages\cryptography\x509\__init__.py", line 7, in <module>
from cryptography.x509 import certificate_transparency
File "C:\Program Files\Python310\lib\site-packages\cryptography\x509\certificate_transparency.py", line 11, in <module>
from cryptography.hazmat.bindings._rust import x509 as rust_x509
ImportError: DLL load failed while importing _rust: Das angegebene Modul wurde nicht gefunden.
%2: %3
Packages
PS C:\> python -m pip list -v
Package Version Location Installer
------------------ --------- -------------------------------------------- ---------
asttokens 2.2.1 c:\program files\python310\lib\site-packages pip
backcall 0.2.0 c:\program files\python310\lib\site-packages pip
certifi 2023.7.22 c:\program files\python310\lib\site-packages pip
cffi 1.15.1 c:\program files\python310\lib\site-packages pip
charset-normalizer 3.2.0 c:\program files\python310\lib\site-packages pip
colorama 0.4.6 c:\program files\python310\lib\site-packages pip
cryptography 41.0.3 c:\program files\python310\lib\site-packages pip
decorator 5.1.1 c:\program files\python310\lib\site-packages pip
executing 1.2.0 c:\program files\python310\lib\site-packages pip
idna 3.4 c:\program files\python310\lib\site-packages pip
ipython 8.14.0 c:\program files\python310\lib\site-packages pip
jedi 0.19.0 c:\program files\python310\lib\site-packages pip
matplotlib-inline 0.1.6 c:\program files\python310\lib\site-packages pip
ntlm-auth 1.5.0 c:\program files\python310\lib\site-packages pip
parso 0.8.3 c:\program files\python310\lib\site-packages pip
pickleshare 0.7.5 c:\program files\python310\lib\site-packages pip
pip 23.2.1 c:\program files\python310\lib\site-packages pip
prompt-toolkit 3.0.39 c:\program files\python310\lib\site-packages pip
pure-eval 0.2.2 c:\program files\python310\lib\site-packages pip
pycparser 2.21 c:\program files\python310\lib\site-packages pip
Pygments 2.16.1 c:\program files\python310\lib\site-packages pip
PyMuPDF 1.22.5 c:\program files\python310\lib\site-packages pip
pyodbc 4.0.39 c:\program files\python310\lib\site-packages pip
pywin32 306 c:\program files\python310\lib\site-packages pip
requests 2.31.0 c:\program files\python310\lib\site-packages pip
requests-ntlm2 6.5.3 c:\program files\python310\lib\site-packages pip
setuptools 68.1.0 c:\program files\python310\lib\site-packages pip
six 1.16.0 c:\program files\python310\lib\site-packages pip
stack-data 0.6.2 c:\program files\python310\lib\site-packages pip
traitlets 5.9.0 c:\program files\python310\lib\site-packages pip
urllib3 2.0.4 c:\program files\python310\lib\site-packages pip
wcwidth 0.2.6 c:\program files\python310\lib\site-packages pip
Environment-variables (left side run as Windows service, right side started directly from Powershell)

Any tip what I'm doing wrong?
Best regards
Steffen