CentOS6.9自带Python2.6.6报错“ValueError: zero length field name in format”的问题

[root@MrYang ~]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from fabric.api import *
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/site-packages/fabric/api.py", line 9, in 
    from fabric.context_managers import (cd, hide, settings, show, path, prefix,
  File "/usr/lib/python2.6/site-packages/fabric/context_managers.py", line 42, in 
    from fabric.state import output, win32, connections, env
  File "/usr/lib/python2.6/site-packages/fabric/state.py", line 9, in 
    from fabric.network import HostConnectionCache, ssh
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 24, in 
    import paramiko as ssh
  File "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 22, in 
    from paramiko.transport import SecurityOptions, Transport
  File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 89, in 
    class Transport(threading.Thread, ClosingContextManager):
  File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 103, in Transport
    _CLIENT_ID = 'paramiko_{}'.format(paramiko.__version__)
ValueError: zero length field name in format

在CentOS6.9上使用Python2.6.6和Python3.6的paramiko第三方库的时候,一直报错如上,经过一番百度的总结如下:

Python官方推荐使用 str.format() 的方式来进行字符串的格式化,所以使用 "{}/n".format(x)的方式处理字符串可会遇到问题。

在Python2(>=2.7)和Python3(>=3.1)中,str.format()方法中的位置参数默认是可以省略的,但是在Python2(<2.7)和Python3(<3.1)中,你必须显示指定(下标从0开始),否则就会出现「zero length field name in format」错误。

"{}CMD".format(os.sep)    #在Python 2.7中可以正常运行#"{0}CMD".format(os.sep)  #在Python<=2.6/3.1中,必须显示指定下标,即便只有一个元素。

参考链接:https://www.aliyun.com/jiaocheng/460757.html

你可能感兴趣的:(python,CentOS,运维)