Python OSError:[WinError 10049]L’;adresse demand和#xE9;EN’;这是我的儿子康特斯特

Python OSError:[WinError 10049]L’;adresse demand和#xE9;EN’;这是我的儿子康特斯特,python,winapi,pysnmp,Python,Winapi,Pysnmp,我正试图获取snmp陷阱,但我得到了OSError:[WinError 10049]错误。任何人都可以帮助我解决此问题,以下是我的全部代码: from pysnmp.entity import engine, config from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity.rfc3413 import ntfrcv snmpEngine = engine.SnmpEngine() TrapAgentAddress=

我正试图获取snmp陷阱,但我得到了OSError:[WinError 10049]错误。任何人都可以帮助我解决此问题,以下是我的全部代码:

from pysnmp.entity import engine, config
from pysnmp.carrier.asyncore.dgram import udp
from pysnmp.entity.rfc3413 import ntfrcv
snmpEngine = engine.SnmpEngine()

TrapAgentAddress='10.17.92.2' #Trap listerner address
Port= 163  #trap listerner port
print("Agent is listening SNMP Trap on "+TrapAgentAddress+" , Port : " +str(Port))
print('--------------------------------------------------------------------------')
config.addTransport(
    snmpEngine,
    udp.domainName + (1,),
    udp.UdpTransport().openServerMode((TrapAgentAddress, Port))
)

#Configure community here
config.addV1System(snmpEngine, 'my-area', 'public')

def cbFun(snmpEngine, stateReference, contextEngineId, contextName,
          varBinds, cbCtx):
    print("Received new Trap message")
    for name, val in varBinds:        
        print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))

ntfrcv.NotificationReceiver(snmpEngine, cbFun)

snmpEngine.transportDispatcher.jobStarted(1)  

try:
    snmpEngine.transportDispatcher.runDispatcher()
except:
    snmpEngine.transportDispatcher.closeDispatcher()
    raise
以下是回溯错误:

Traceback (most recent call last):
  File "C:\Users\oussama.belhadje.stg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pysnmp\carrier\asyncore\dgram\base.py", line 55, in openServerMode
    self.socket.bind(iface)
OSError: [WinError 10049] L’adresse demandée n’est pas valide dans son contexte
在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "c:/Users/oussama.belhadje.stg/Desktop/pysnmp/snmp_trap_receiver.py", line 15, in <module>
    udp.UdpTransport().openServerMode((TrapAgentAddress, Port))
  File "C:\Users\oussama.belhadje.stg\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pysnmp\carrier\asyncore\dgram\base.py", line 57, in openServerMode
    raise error.CarrierError('bind() for %s failed: %s' % (iface, sys.exc_info()[1],))
pysnmp.carrier.error.CarrierError: bind() for ('10.17.92.2', 163) failed: [WinError 10049] L’adresse demandée n’est pas valide dans 
son contextecaused by <class 'OSError'>: [WinError 10049] L’adresse demandée n’est pas valide dans son contexte
回溯(最近一次呼叫最后一次):
文件“c:/Users/oussama.belhadje.stg/Desktop/pysnmp/snmp\u trap\u receiver.py”,第15行,在
udp.udptTransport().openServerMode((TrapAgentAddress,端口))
文件“C:\Users\oussama.belhadje.stg\AppData\Local\Programs\Python\Python38-32\lib\site packages\pysnmp\carrier\asyncore\dgram\base.py”,第57行,在openServerMode下
引发错误。CarrierError(%s的“bind()失败:%s%”(iface,sys.exc_info()[1],)
pysnmp.carrier.error.carrierror:bind()for('10.17.92.2',163)失败:[WinError 10049]L'adrese demandée n'est pas valide dans
儿子康特斯特由:[WinError 10049]L'Adrese demandée n'est pas valide dans儿子康特斯特引起

请编辑您的帖子以提供完整的堆栈跟踪错误。请编辑您的帖子以包含堆栈跟踪,由于格式和字符限制,评论不是放置它们的位置。我个人没有使用pysnmp,但是,您得到了一个绑定错误,并且使用了一个名为openServerMode的方法,这表明您在这里使用了错误的方法。Bind将被调用来打开一个侦听套接字以接受传入的连接,而不是像我认为的那样连接到远程系统。