Python Forum

Full Version: Why does my code only work once?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a little python script that checks my current IPv4 DNS Server address. It's working just fine. I use the wmi package.

Now: I use this script in Kodi. And first time it runs, it runs perfectly. But the second time I get a weird error.

Why does my code work the first time, but not the following attempts?

Hope you guys can help me. I'm lost.

my script:

Quote:import wmi

nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True);
nic = nic_configs[0];
dns = nic.DNSServerSearchOrder[0];

the error:

Quote: Error Type: <type 'exceptions.AttributeError'>
Error Contents: 'NoneType' object has no attribute 'platform'
Traceback (most recent call last):
File "C:\Python\Lib\site-packages\mytest.py", line 22, in <module>
import wmi
File "C:\Python\Lib\site-packages\wmi.py", line 88, in <module>
from win32com.client import GetObject, Dispatch
File "C:\Python\Lib\site-packages\win32com\__init__.py", line 6, in <module>
import pythoncom
File "C:\Python\Lib\site-packages\pythoncom.py", line 3, in <module>
pywintypes.__import_pywin32_system_module__("pythoncom", globals())
File "C:\Python\Lib\site-packages\pywintypes.py", line 20, in __import_pywin32_system_module__
if not sys.platform.startswith("win32"):
AttributeError: 'NoneType' object has no attribute 'platform'
-->End of Python script error report<--