python3支持byte类型,python2不支持。在python3中,telnet客户端向远程服务器发送的str要转化成byte,从服务器传过来的byte要转换成str,但是在python2不清楚怎么回事。。。解决方法:

1.用python2的编译器

2.str对象和bytes对象可以使用.encode() (str -> bytes) or .decode() (bytes -> str)方法相互转化

>>> b = b'china'
>>> type(b)
<type 'bytes'>
>>> s = b.decode()
>>> s
'china'
>>> b1 = s.encode()
>>> b1
b'china' 附上具体的代码:
tn.read_until(b'login:')//读取到二进制字符串
    tn.write((username + '\n').encode())//将字符串变成二进制字符串发送出去
    #输入密码
    tn.read_until(b'Password:')
    tn.write((password + '\n').encode())
如果有要输入的命令,也要转化成二进制字符串发送出去。比如configure 要b'configure
 

python编写telnet登陆出现TypeError:'str' does not support the buffer interface的更多相关文章

  1. Python 3中套接字编程中遇到TypeError: 'str' does not support the buffer interface的解决办法

    转自:http://blog.csdn.net/chuanchuan608/article/details/17915959 目前正在学习python,使用的工具为python3.2.3.发现3x版本 ...

  2. python——TypeError: 'str' does not support the buffer interface

    import socket import sys port=51423 host="localhost" data=b"x"*10485760 #在字符串前加 ...

  3. python3 TypeError: 'str' does not support the buffer interface in python

    http://stackoverflow.com/questions/38714936/typeerror-str-does-not-support-the-buffer-interface-in-p ...

  4. python3使用套接字遇到TypeError: 'str' does not support the buffer interface如何解决

    这是我查看的博客 http://blog.csdn.net/chuanchuan608/article/details/17915959 直接引用里面的关键语句: When you use clien ...

  5. 使用 Python 编写登陆接口

    # 使用 Python 编写登陆接口# Create Date: 2017.10.31 Tuesday# Author: Eric Zhao# -*- coding:utf-8 -*-'''编写登陆接 ...

  6. python编写简单的html登陆页面(4)

    python编写简单的html登陆页面(4)   1  在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将动态态分配数据,建立表格,存放学生信息 2 实现的效果如下: 3  动 ...

  7. python编写简单的html登陆页面(3)

    1  在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将静态分配数据,建立表格,存放学生信息 2  加载到静态数据 3  html的编写直接在表格里添加一组数据就行了 4  V ...

  8. python编写简单的html登陆页面(2)

    1  在python编写简单的html登陆页面(1)的基础上在延伸一下: 可以将动态分配数据,实现页面跳转功能: 2  跳转到新的页面:return render_template('home1.ht ...

  9. Python的字符串修改报错:TypeError: 'str' object does not support item assignment

    Python中想修改字符串的最后一个字符,使用name[-1] = 'e'来实现,运行后报错. 报错内容是:TypeError: 'str' object does not support item ...

随机推荐

  1. 利用一些码农Trick去搞一搞G和T的单词

    根据自然语言处理中的Zipf统计定律,在自然语言的语料库里,一个单词出现的频率与它在频率表里的排名成反比.因此,我们有理由认为,可以根据这个频率表进行一下排序,以及purning.由于精力有限,没有足 ...

  2. 创建类模式(五):单例(Singleton)

    定义 确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 单例模式一般情况下通过使用private的构造函数确保了在一个应用中只产生一个实例,并且是自行实例化. 和静态变量的区别 虽然 ...

  3. JAX-RS入门 一 :基础

    简介 JAX-RS是一套用java实现REST服务的规范,提供了一些标注将一个资源类,一个POJOJava类,封装为Web资源.标注包括: @Path,标注资源类或方法的相对路径 @GET,@PUT, ...

  4. 用DependanceProperty做Dynamic换Icon

    1:做Icon用Canvas还是DrawingBrush? Canvas的例子:

  5. 组合View Controller时遇到的一点问题

    View Controller的组合应用其实很常见了,比如说Tab bar controller和Navigation view controller的组合使用,像这种一般都是Navigation v ...

  6. Putty 工具 保存配置的 小技巧

    用Putty 已经很长时间了,但一直被一个问题困扰,有时候是懒得去弄,反正也不怎么碍事,今天小研究了下,把这个问题解决了,心里也舒服了. Putty是一个免费小巧的Win32平台下的telnet,rl ...

  7. VNC 抓取远程桌面

    VNC (Virtual Network Computing)是虚拟网络计算机的缩写.VNC 是一款优秀的远程控制工具软件,由著名的 AT&T 的欧洲研究实验室开发的.VNC 是在基于 UNI ...

  8. asp.net解决:当前上下文中不存在名称“Session”

    第一种方法:将使用session的类页面继承 System.Web.UI.Page类,方法:public class AddUser : System.Web.UI.Page 第二种方法:在page里 ...

  9. 利用FluorineFx的ByteArray上传图片

    Flex端利用new PNGEncoder().encode(bitmapData)将png图片转换为ByteArray,然后传给服务器,服务端需要定义一个public ByteArray Uploa ...

  10. [ES6] 15. Generators -- 2

    Using for..of statement: function* greeting(){ console.log(`Generators are "lazy"`); yield ...