推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
CR7sun
V2EX  ›  Python

请问 Python 利用 telnetlib 登录被 ACL 拒绝该如何处理异常?

  •  
  •   CR7sun · Dec 24, 2020 · 2483 views
    This topic created in 2109 days ago, the information mentioned may be changed or developed.

    请问用 python 的 telnetlib 进行 telnet 登录时,连接上去又被 ACL 拒了然后代码报错。请问该如何处理这个异常,结束这次登陆尝试?

     try:
        self.tn = telnetlib.Telnet(host_ip,port=23,timeout=2)
     except:
        logging.warning("failed to connect to host:%s" %host_ip)
        return False
     self.tn.read_until(b'Username:', timeout=3)
     self.tn.write(user_name.encode('ascii') + b'\n')
     self.tn.read_until(b'Password:', timeout=3)
     self.tn.write(pass_word.encode('ascii') + b'\n') 
    

    手动登录测试截图:

    https://imgchr.com/i/rgKksH

    代码报错截图:

    https://imgchr.com/i/rgKFQe

    1 replies  •  2020-12-25 11:12:13 +08:00
    julyclyde
        1
    julyclyde  
       Dec 25, 2020
    这种都是先建立连接再断开连接的。错误信息写的很明白啊 EOFError 你试试 except 这个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   780 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:42 · PVG 05:42 · LAX 14:42 · JFK 17:42
    ♥ Do have faith in what you're doing.