首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >telnetlib的Python错误

telnetlib的Python错误
EN

Stack Overflow用户
提问于 2020-01-09 18:51:03
回答 1查看 275关注 0票数 0

我对python的库telnetlib有多个错误。

当我在repl中使用它时,下面是我输入的代码:

代码语言:javascript
复制
import telnetlib
telnetlib.Telnet("<an_ip>", <a_port>) as tn:
  write("SYST:BEEP")

它返回以下错误:

代码语言:javascript
复制
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

现在,奇怪的是,当我执行以下脚本时:

代码语言:javascript
复制
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)

我有以下错误,我每次导入telnetlib时都会有错误...

代码语言:javascript
复制
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'

我使用的是python v3.7.5。我将正确的信息替换为。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-03-04 06:37:41

看起来您已经在/home/vpecatte/dev/soft/soft/types.py中安装了自己的types模块,这与Python内置的types模块冲突。最好的解决方案可能是重命名该types模块。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59662300

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档