LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python Node Error 1671: class SystemError, bad argument to internal function.

Hey Fancy Folk,

 

I’m new to using Python in LabVIEW and am running into an issue.  I am calling some code and if I don’t have an “output” wired to the python node, my code executes fine.  But If I do have an output wired, I get a 1671 error seen below.

“Python Node in External Calibration TCP.lvclass:Run Code.vi->OO Python setup.vi<APPEND>

 

Python returned the following error: <class 'SystemError'>

D:\a\1\s \Objects\listobject.c:186: bad argument to internal function”

 

Note, D:\a\1 does exist on an external hard drive but the s \Objects\listobject doesn’t.

Here are 2 images, one of the LV code w/ no output wired and the other with the output wired.  The only thing that I changed was removing the string array and adding a variant constant so my code could run. 

Matt_AM_0-1661189551067.png

 

Matt_AM_1-1661189551073.png

 

 

My original thought for what is wrong is that I was putting in the wrong “output” for my python node, but I have verified from the author of the script and pycharm debugging that I am expecting a list of strings, which should be an array of strings in LV.  However, it also looks like the list has __len__ when debugging in pycharm and I’m not sure if python sends that as well.  If so, the return would be an array of strings and an int, which sounds like I’ll need to make a cluster.  See images below.

Matt_AM_2-1661189551075.png

 

Matt_AM_3-1661189551075.png

 

 

Thanks,

Matt

If you want to find useful posts, you have to make useful posts. Please try to provide how you solve your posted problems for future users, a better forum helps the community out.
Message 1 of 5
(4,093 Views)

Hi Matt,

 

Got kind of the same problem, all works until I try to output the result of my function. I think someone has identified the reason for it in another threat:

 

https://forums.ni.com/t5/LabVIEW/Error-1671-Python-Node/m-p/4312840#M1261485 

 

I'm personally reluctant to use his solution because it involves modifying the python script, which is not mine and is also used by some other apps, but it might work for you.

 

0 Kudos
Message 2 of 5
(3,392 Views)

@derGogo

 

To be honest, it has been a really long time since I modified my code to get it working.  I don't exactly remember what fixed my issue.  That being said, based on the images I provided here and my current working code, I had to define how large the array of strings was in LV for the returned variable (previous code just used a string to build array and current code uses string to init a 32 element long string array).  I also changed the input variables from ints/doubles/strings to all strings then casted them to their proper form in the python code (python is not a strict type language so you can convert types super easily which has screwed me over in the past by defining a variable as a double with value of 10 then dividing that 2 which caused the variable to become int 5.  to solve this I casted the result as a double via double(10/2) or whatever the proper function name is).  

 

I by no means am an expert in LV with python or python in general.  I understand python enough to work in it.  I remember that I had to modify the python code I got to accept the list of strings then I also had to change how python returned things to create a list of strings where I casted the returned python values in LV to their proper type.  Basically my solution was to work through string manipulation instead of figuring out what was the true root cause of the problem.  I got it working, so I moved on.  

 

Unfortunately, I think you'll need to modify the python script to get things working properly in LV.  The image below is a snippet of my code which should match the previous images. 

 

Matt_AM_0-1687525510211.png

 

 

Matt

If you want to find useful posts, you have to make useful posts. Please try to provide how you solve your posted problems for future users, a better forum helps the community out.
Message 3 of 5
(3,381 Views)

After checking the help of the labview python node, and discussing a bit with an AI (phind.com) I think I found the problem, and the AI proposed the sollution. Again, it involves modifying the python code unfortunately:

 

The Python Node help states:

"

Calling Conventions

This node converts integers, strings, and Booleans to the corresponding data types in Python, converts arrays to lists or NumPy arrays, and converts clusters to tuples."

 

So what phind.com proposed is:

 

"

Based on the provided search results, the LabVIEW Python node converts arrays to lists. This could be the reason for the error you encountered when trying to return an array from the Python script.

In LabVIEW, when a Python script is called from a LabVIEW Python node, arrays are automatically converted to lists before being passed to the Python script. Similarly, when the Python script returns a result, the returned list is converted back to an array in LabVIEW.

To work around this issue and ensure compatibility between the LabVIEW Python node and the Python script, you can modify your Python script to return a list instead of an array. This way, the LabVIEW Python node will be able to handle the returned value correctly.

Here's an example of how you can modify the Python script to return a list instead of an array:

 

derGogo_0-1687527129948.png

By using the list() function in Python, you can convert the array to a list before returning it from the function.

 

I think it's kind of the generic version of the answer I found in the other thread. I think the point is: Python interpretes instructions but labview doesn't, it needs things to be hard defined very explicitely. I appologize in advance if I'm wrong. Just struggling too, like everyone facing this issue apparently...

 

Message 4 of 5
(3,378 Views)

@Matt ahh sorry, I saw you message only after writing mine, but yes, you also mentioned defining the list() more explicitly in python, and it seems like that's really the point with that bug. Anyway, happy you solved your problem. Let's see if I can modify my Python w/o f***ing up all the apps using it!

 

EPILOGUE: it worked and the other apps calling this script seem to still work too.

0 Kudos
Message 5 of 5
(3,376 Views)