SSL.py TypeError: data must be a byte string
来源:互联网 发布:淘宝产品图价格 编辑:程序博客网 时间:2024/05/22 01:35
做爬虫已经一段时间了,不过一直抓的是http的网页,昨天突然有了一个https的需求,因为维基用http查敏感词会被封(你懂得),所以必须要用https.
不过抓的时候报了一个错,HTTPS not supported: install pyopenssl library
按照提示安装pyOpenSSL,可是安装后又报错
难道是Twisted有问题?按照twisted手册试试ssl协议,copy例子运行
from twisted.internet import ssl, reactor
from twisted.internet.protocol import ClientFactory, Protocol
class EchoClient(Protocol):
def connectionMade(self):
print "hello, world"
ss="hello"
self.transport.write(str.encode(ss))
def dataReceived(self, data):
print "Server said:", data
self.transport.loseConnection()
class EchoClientFactory(ClientFactory):
protocol = EchoClient
def clientConnectionFailed(self, connector, reason):
print "Connection failed - goodbye!"
reactor.stop()
def clientConnectionLost(self, connector, reason):
print "Connection lost - goodbye!"
reactor.stop()
if __name__ == '__main__':
factory = EchoClientFactory()
reactor.connectSSL('208.80.154.224', 80, factory, ssl.ClientContextFactory())
reactor.run()
报了一样的错
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 84, in callWithLoggerreturn callWithContext({"system": lp}, func, *args, **kw)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/python/log.py", line 69, in callWithContext
return context.call({ILogContext: newCtx}, func, *args, **kw)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 59, in callWithContext
return self.currentContext().callWithContext(ctx, func, *args, **kw)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/python/context.py", line 37, in callWithContext
return func(*args,**kw)
--- <exception caught here> ---
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
why = getattr(selectable, method)()
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 177, in doWrite
return Connection.doWrite(self)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 428, in doWrite
result = abstract.FileDescriptor.doWrite(self)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/internet/abstract.py", line 115, in doWrite
l = self.writeSomeData(self.dataBuffer)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 181, in writeSomeData
return Connection.writeSomeData(self, data)
File "/usr/local/lib/python2.7/site-packages/Twisted-10.0.0-py2.7-linux-x86_64.egg/twisted/internet/tcp.py", line 474, in writeSomeData
return self.socket.send(buffer(data, 0, self.SEND_LIMIT))
File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 947, in send
raise TypeError("data must be a byte string")
exceptions.TypeError: data must be a byte string
把Twisted升级为14.0.0版本,问题解决
原来是版本不兼容的原因
查看pyOpenSSL版本为0.14,经测试也可以将pyOpenssL将将为0.11也可运行。
- SSL.py TypeError: data must be a byte string
- TypeError: Path must be a string. Received undefined
- TypeError: dist must be a Distribution instance
- 学习node时报错throw new TypeError('first argument must be a string or Buffer');
- python错误:TypeError: string indices must be integers
- TypeError: argument 1 must be string or buffer, not instance
- Python TypeError: must be string or buffer, not dict
- openstack Swift Grizzly TypeError: dist must be a Distribution instance
- TypeError: context must be a dict rather than Context.
- TypeError: unbound method a() must be called with A instance as first argument (got nothing instead)
- TypeError: view must be a callable or a list/tuple in the case of include()
- TypeError: view must be a callable or a list/tuple in the case of include().
- TypeError: view must be a callable or a list/tuple in the case of include().解决办法
- TypeError: view must be a callable or a list/tuple in the case of include()
- TypeError: view must be a callable or a list/tuple in the case of include()
- python-rrdtool创建rrd文件的TypeError: argument 0 must be string 错误
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- Uncaught TypeError: Super expression must either be null or a function, not undefine
- myEclipse注册小工具
- ***(leetcode) Climbing Stairs
- CentOS-6.4-minimal版中Apache-2.2.29配置请求转发
- 常见算法在实际项目中的应用
- 正则表达式30分钟入门教程
- SSL.py TypeError: data must be a byte string
- 配置ssh公钥访问oschina
- css常用属性
- 使用接插件需要注意的问题
- 用C++程序检查机器的字节序(大端或小端)
- 句子录音打分代码参考
- DSP6000的上电及供电
- spring mvc 图片上传,图片压缩、跨域解决、 按天生成目录 ,删除,限制为图片代码等相关配置
- linux下图解挂载U盘全过程