12-20-2024 09:28 AM
I'm using Python along with the Microsoft MSAL library to access a SharePoint site via Graph API. As part of the authentication process, Python launches a web browser for the user to sign-in to their Microsoft account, and it listens for a callback on a port (I can specify the number) for the authentication result. This works flawlessly in Python, but when calling the module through the Python Node in LabVIEW, it immediately throws an error that it's unable to listen to the specified port.
Is there any resolution to this issue? Or is this just not possible using the Python Node?
For reference, I'm using LabVIEW 2019 and Python 3.8.10. The MSAL method being used is PublicClientApplication.acquire_token_interactive.
Solved! Go to Solution.
12-20-2024 11:04 AM
Instead of using the Python Node, try calling the Python script directly using the exe VI. This will cause the script to use the Python instance associated with your PATH variable. The advantage of this is that you have more control over the Python environment associated with the PATH. Also, depending on how you are calling the Python script that works, you might be using the same Python environment so it has a better chance of working.
12-20-2024 11:06 AM
You can call the Python module like this
01-15-2025 03:02 PM
I've tested this quite a bit now and it looks like it will work BUT there's a condition: the working directory has to be set to something like the base user directory (User Home in Get System Directory.vi for example). Without setting that, I kept getting the following error: "Can't listen on port 60407. You may try port 0."
I'm assuming that this has something to do with the environment in which the token_cache.bin file is being created, which acts as persistent storage of the MSAL authentication data so the user doesn't need to sign in every single time. I'm really unsure though as the only reference I could find when Googling the issue is an Azure bug which mentions deleting the token cache file and that correcting the issue.
Regardless, I thought I would mention it here in case anyone else runs into a similar issue.