0

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:

import wmi

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

the error:

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<--
NoIdeaJoe
  • 19
  • 5
  • Never used this library, but if it is only DNS address you are after try this: https://stackoverflow.com/questions/50015586/python-dns-server-ip-address-query – sleepyhead Sep 01 '19 at 14:06
  • Or you can try to use [dnspython](https://pypi.org/project/dnspython/). – Drake Wu Sep 02 '19 at 07:08
  • been there, done that. Dnspython doesn't do that. I even asked at their github. – NoIdeaJoe Sep 02 '19 at 08:36
  • The error prompt indicates that `sys` is a `"Nonetype"` and I checked all the .py libraries metioned and there is no possible exception and "sys-related" definition. I guess your code uses the `sys` variable and conflicts with the sys module imported. Since your code snippet is from Line 22, you'd better post the previous code as well. – Drake Wu Sep 04 '19 at 02:27

0 Answers0