So I am trying to run a python script from my .NET Core App.
When the method that involves functions and classes, that are included in the IronPython Library, is invoked, it gives me the following error message :
Could not load file or assembly 'IronPython, Version=2.7.9.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1'. Operation is not legal in the current state. (Exception from HRESULT: 0x80131509)
I had installed the IRON Python library for .NET using the Nuget Package Manager. Also, the present version of python installed in my system is 3.7.3
Have already tried downgrading the version of python from 3.7.3 to 2.7
Have tried to explicitly register the .dll for IronPython using regsvr32.exe
public async Task<string> FunctionHandler(S3Event evnt, ILambdaContext
context)
{
var s3Event = evnt.Records?[0].S3;
if(s3Event == null)
{
return null;
}
try
{
var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);
string recording_key = "some value";
string DownloadURL = await this.GenerateTranscript(recording_key);
TranscriptionJob tj = JsonConvert.DeserializeObject<TranscriptionJob>(DownloadURL);
File.WriteAllText(@"D:/Audio/NewFileLocation.txt", tj.Transcript.TranscriptFileUri);
return response.Headers.ContentType;
}
catch(Exception e)
{
context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function.");
context.Logger.LogLine(e.Message);
context.Logger.LogLine(e.StackTrace);
throw;
}
}
public async Task<string> GenerateTranscript(string testUrl)
{
var Engine = Python.CreateEngine();
var script = @"~/TranscriptGenerate/PythonTranscript.py";
var source = Engine.CreateScriptSourceFromFile(script);
Engine.GetSysModule().SetVariable("objurl", testUrl);
var result = Engine.Runtime.IO;
var errors = new MemoryStream();
result.SetErrorOutput(errors, Encoding.Default);
var results = new MemoryStream();
result.SetOutput(results, Encoding.Default);
var scope = Engine.CreateScope();
await source.Execute(scope);
//source.Execute(scope);
string str(byte[] x) => Encoding.Default.GetString(x);
string response_from_script = str(results.ToArray());
return response_from_script;
}
Expected Result: My console should navigate to the GenerateTranscript method without any exceptions while debugging in VS2019.
Actual Result: On reaching the GenerateTranscript method call from the FunctionHandler method I am encountering the following error.
Any help, in this case, would be welcome. Thanks in advance
User contributions licensed under CC BY-SA 3.0