Fatal Python Error: _Py_HashRandomization_Init when calling Python from C# under IIS

  asp.net, c++, iis, python, windows

I have a web application based on C#, ASP.NET and Python that is currently running under IIS Express without problems on Windows 2016 Server.

When I publish it under IIS, I get problems with calling Python from C#. Using a simple Logger, I managed to get the following error information:

Error: Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python
Python runtime state: preinitialized

How can I get Python running under IIS? I have seen that such problems can occur when SYSTEMROOT is not on PATH, but in this case it is, for both IIS Express and IIS.

I am using Python 3.9 and ASP.NET 4.7.2 on Windows Server 2016.

Source: Windows Questions

LEAVE A COMMENT