Python Forum
Working socket() program...isn't
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working socket() program...isn't
#7
(Nov-01-2019, 07:14 PM)nilamo Wrote: Support for using sockets with the context manager (with-block) was added in 3.2. You said you've checked that they're both at least 3.6, but could you double check the python versions involved?

I wouldn't think that'd be the issue, though, as the error would probably mention __enter__ instead of __exit__.

Do you happen to have a file named "socket.py" in your path? Maybe you're importing the wrong thing...

FYI (and maybe this is obvious from my 'outputs') I'm running in a virtual environment for Py3, but I see where you're going with this. So I added

print(sys.version_info)
print(socket.__file__)
just above the first 'if', adn that yields:

Output:
(pagesniff) [a-ptrivino@insecpydev pagesniff]$ sudo python sniffsms.py server sys.version_info(major=2, minor=7, micro=5, releaselevel='final', serial=0) /usr/lib64/python2.7/socket.pyc ['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__weakref__', '_sock', 'accept', 'bind', 'close', 'connect', 'connect_ex', 'dup', 'family', 'fileno', 'getpeername', 'getsockname', 'getsockopt', 'gettimeout', 'listen', 'makefile', 'proto', 'recv', 'recv_into', 'recvfrom', 'recvfrom_into', 'send', 'sendall', 'sendto', 'setblocking', 'setsockopt', 'settimeout', 'shutdown', 'type'] Traceback (most recent call last): File "sniffsms.py", line 31, in <module> with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as transfer: AttributeError: __exit__ (pagesniff) [a-ptrivino@insecpydev pagesniff]$
My path (from 'env')
Output:
PATH=/home/a-ptrivino/Py3hole/pagesniff/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/puppetlabs/bin:/home/a-ptrivino/.local/bin:/home/a-ptrivino/bin
Thanks for this, BTW...

I kinda see where this is headed. So I su'd and navigated to the directory, and ran it as root:

Output:
(pagesniff) [root@insecpydev pagesniff]# python sniffsms.py server sys.version_info(major=3, minor=6, micro=6, releaselevel='final', serial=0) /usr/lib64/python3.6/socket.py ['__class__', '__del__', '__delattr__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__weakref__', '_accept', '_check_sendfile_params', '_closed', '_decref_socketios', '_io_refs', '_real_close', '_sendfile_use_send', '_sendfile_use_sendfile', 'accept', 'bind', 'close', 'connect', 'connect_ex', 'detach', 'dup', 'family', 'fileno', 'get_inheritable', 'getpeername', 'getsockname', 'getsockopt', 'gettimeout', 'listen', 'makefile', 'proto', 'recv', 'recv_into', 'recvfrom', 'recvfrom_into', 'recvmsg', 'recvmsg_into', 'send', 'sendall', 'sendfile', 'sendmsg', 'sendmsg_afalg', 'sendto', 'set_inheritable', 'setblocking', 'setsockopt', 'settimeout', 'shutdown', 'timeout', 'type'] ^CTraceback (most recent call last): File "sniffsms.py", line 39, in <module> conn, client = transfer.accept() File "/usr/lib64/python3.6/socket.py", line 205, in accept fd, addr = self._accept() KeyboardInterrupt (pagesniff) [root@insecpydev pagesniff]#
It runs fine. Wall Wall Wall
Reply


Messages In This Thread
Working socket() program...isn't - by ptrivino - Nov-01-2019, 01:50 AM
RE: Working socket() program...isn't - by ptrivino - Nov-01-2019, 05:07 PM
RE: Working socket() program...isn't - by ptrivino - Nov-01-2019, 06:54 PM
RE: Working socket() program...isn't - by nilamo - Nov-01-2019, 07:14 PM
RE: Working socket() program...isn't - by ptrivino - Nov-01-2019, 07:51 PM
RE: Working socket() program...isn't - by nilamo - Nov-01-2019, 08:58 PM
RE: Working socket() program...isn't - by ptrivino - Nov-01-2019, 10:35 PM
RE: Working socket() program...isn't - by ptrivino - Nov-02-2019, 12:25 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020