我从Kalle的视频上看到了这个有趣的想法。它是关于当某人的IP连接到网络时提醒你
import sys
import subprocess
import os
from decouple import config
IP_NETWORK = config('IP_NETWORK')
IP_DEVICE = config('IP_DEVICE')
proc = subprocess.Popen(["ping", IP_NETWORK],stdout=subprocess.PIPE)
while True:
line = proc.stdout.readline()
if not line:
break
#the real code does filtering here
connected_ip = line.decode('utf-8').split()[3]
if connected_ip == IP_DEVICE:
subprocess.Popen(["say", "Linnea just connected to the network"])误差
Traceback (most recent call last):
File "C:\Users\utkar\Downloads\net-listen.py", line 6, in <module>
IP_NETWORK = config('IP_NETWORK')
File "C:\Users\utkar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\decouple.py", line 199, in __call__
return self.config(*args, **kwargs)
File "C:\Users\utkar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\decouple.py", line 83, in __call__
return self.get(*args, **kwargs)
File "C:\Users\utkar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\decouple.py", line 68, in get
raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option))
decouple.UndefinedValueError: IP_NETWORK not found. Declare it as envvar or define a default value.
Process returned 1 (0x1) execution time : 0.150 s
Press any key to continue . . .发布于 2020-08-15 13:08:27
好像你忘了设置一个settings.ini。它应该是这样的:
[settings]
IP_Network=YOUR NETWORK IP
IP_DEVICE=YOUR DEVICE IPhttps://stackoverflow.com/questions/63321594
复制相似问题