Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyinstaller .exe errors when sending trap #39

Open
vprong opened this issue Feb 22, 2017 · 2 comments
Open

Pyinstaller .exe errors when sending trap #39

vprong opened this issue Feb 22, 2017 · 2 comments

Comments

@vprong
Copy link

vprong commented Feb 22, 2017

I'm getting error "TypeError: getsockaddrarg() takes exactly 2 arguments (6 given)" when sending a trap after compiling into a windows .exe with Pyinstaller and the --onefile option. This is with the example code at http://pysnmp.sourceforge.net/examples/v3arch/asyncore/agent/ntforg/snmp-versions.html#snmpv1-trap . It works fine as a plain .py script.

if I add debugging to pysnmp/carrier/asyncore/dgram/base.py line 142

try:
            print("transportAddress: " + str(transportAddress))
            self._sendto(
                self.socket, outgoingMessage, transportAddress
            )

I see the following when it works as a .py script:
transportAddress: ('10.6.105.121', 162)

And the following when it fails as a Windows .exe

transportAddress: (10, 6, 105, 121, 0, 162)
Traceback (most recent call last):
  File "site-packages\pysnmp\carrier\asyncore\dispatch.py", line 46, in runDispatcher
  File "asyncore.py", line 212, in loop
  File "asyncore.py", line 159, in poll
  File "asyncore.py", line 95, in write
  File "asyncore.py", line 91, in write
  File "asyncore.py", line 461, in handle_write_event
  File "site-packages\pysnmp\carrier\asyncore\dgram\base.py", line 144, in handle_write
  File "site-packages\pysnmp\carrier\asyncore\dgram\base.py", line 35, in <lambda>
TypeError: getsockaddrarg() takes exactly 2 arguments (6 given)

If I modify base.py to fix transportAddress it starts working as a windows .exe

            print("transportAddress: " + str(transportAddress))
            if len(transportAddress) == 6:
              transportAddress = ( '.'.join(map(str,transportAddress[0:4])), transportAddress[5])
              print("NEW transportAddress: " + str(transportAddress))
            self._sendto(
                self.socket, outgoingMessage, transportAddress
            )
transportAddress: (10, 6, 105, 121, 0, 162)
NEW transportAddress: ('10.6.105.121', 162)

I'm not sure if this is necessarly an issue with pysnmp, pyinstaller, python on Windows, or if I should be adding additional code if I plan to compile to .exe

@etingof
Copy link
Owner

etingof commented Feb 22, 2017

There have been some relevant changes in the latest released pysnmp (4.3.3)... With which pysnmp version you are experiencing this crash? What pyasn1 version you are using? Are you packing the same pysnmp/pyasn1 versions into your PyInstaller executable?

The socket address conversion is probably happening here or here. It looks like this conversion is not really invoked so that serialized address (4+2 octets) is reaching the low-level socket code.

@vprong
Copy link
Author

vprong commented Feb 26, 2017

Here's the output of pip freeze

C:\Python34\Scripts> .\pip.exe freeze
future==0.16.0
pefile==2016.3.28
ply==3.10
pyasn1==0.2.2
pycrypto==2.6.1
pycryptodome==3.4.5
pyinstaller==3.3.dev0
pypiwin32==219
pysmi==0.0.7
pysnmp==4.3.3

If I downgrade to pysnmp version 4.3.0 and run the same code I will get the same TypeError without compiling to .exe

testtrap.txt

image

output of running script on 4.3.0
Notification is scheduled to be sent
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\pysnmp-4.3.0-py3.4.egg\pysnmp\carrier\asyncore\dispatch.py", line 37, in runDispat
cher
File "C:\Python34\lib\asyncore.py", line 212, in loop
poll_fun(timeout, map)
File "C:\Python34\lib\asyncore.py", line 159, in poll
write(obj)
File "C:\Python34\lib\asyncore.py", line 95, in write
obj.handle_error()
File "C:\Python34\lib\asyncore.py", line 91, in write
obj.handle_write_event()
File "C:\Python34\lib\asyncore.py", line 461, in handle_write_event
self.handle_write()
File "C:\Python34\lib\site-packages\pysnmp-4.3.0-py3.4.egg\pysnmp\carrier\asyncore\dgram\base.py", line 125, in handle
_write
File "C:\Python34\lib\site-packages\pysnmp-4.3.0-py3.4.egg\pysnmp\carrier\asyncore\dgram\base.py", line 25, in <lambda

TypeError: getsockaddrarg() takes exactly 2 arguments (6 given)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants