0

I have multiple errors with python's library telnetlib.

When I use it from the repl, here is the code I enter:

import telnetlib
telnetlib.Telnet("<an_ip>", <a_port>) as tn:
  write("SYST:BEEP")

It retrurns the following error:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/local/lib/python3.6/telnetlib.py", line 287, in write
    if IAC in buffer:
TypeError: 'in <string>' requires string as left operand, not bytes

Now, something which is strange is when I execute the following script:

import telnetlib

def beep(tn):
    """Beep the pulse generator."""
    tn.write("SYST:BEEP\n")

# Main for test purpose
if __name__ == "__main__":
    with telnetlib.Telnet("<ip>", <port>) as tn:
        beep(tn)

I have the following error and I have it each time I import telnetlib...

raceback (most recent call last):
  File "test.py", line 1, in <module>
    import telnetlib
  File "/usr/lib/python3.7/telnetlib.py", line 37, in <module>
    import socket
  File "/usr/lib/python3.7/socket.py", line 53, in <module>
    from enum import IntEnum, IntFlag
  File "/usr/lib/python3.7/enum.py", line 2, in <module>
    from types import MappingProxyType, DynamicClassAttribute
  File "/home/vpecatte/dev/soft/soft/types.py", line 1, in <module>
    from typing import *
  File "/usr/lib/python3.7/typing.py", line 28, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
  File "/usr/lib/python3.7/re.py", line 143, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
    if not enabled():
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
    import re
  File "/usr/lib/python3.7/re.py", line 122, in <module>
    import enum
  File "/usr/lib/python3.7/enum.py", line 2, in <module>
    from types import MappingProxyType, DynamicClassAttribute
  File "/home/vpecatte/dev/soft/soft/types.py", line 1, in <module>
    from typing import *
  File "/usr/lib/python3.7/typing.py", line 31, in <module>
    from types import WrapperDescriptorType, MethodWrapperType, MethodDescriptorType
ImportError: cannot import name 'WrapperDescriptorType' from 'types' (/home/vpecatte/dev/soft/soft/types.py)

Original exception was:
Traceback (most recent call last):
  File "pulse_generator.py", line 1, in <module>
    import telnetlib
  File "/usr/lib/python3.7/telnetlib.py", line 37, in <module>
    import socket
  File "/usr/lib/python3.7/socket.py", line 53, in <module>
    from enum import IntEnum, IntFlag
  File "/usr/lib/python3.7/enum.py", line 2, in <module>
    from types import MappingProxyType, DynamicClassAttribute
  File "/home/vpecatte/dev/soft/soft/types.py", line 1, in <module>
    from typing import *
  File "/usr/lib/python3.7/typing.py", line 28, in <module>
    import re as stdlib_re  # Avoid confusion with the re we export.
  File "/usr/lib/python3.7/re.py", line 143, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

I use python v3.7.5. I replaced correct informations by , .

Thank you for your help.

1 Answers1

0

Looks like you have installed your own types module in /home/vpecatte/dev/soft/soft/types.py which conflicts with the Python built-in types module. The best solution is probably to rename that types module.

Cito
  • 5,365
  • 28
  • 30