The problem of “value error: zero length field name in format” in Python 2.6.6 of CentOS 6.9

[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 "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/fabric/api.py", line 9, in <module>
    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 <module>
    from fabric.state import output, win32, connections, env
  File "/usr/lib/python2.6/site-packages/fabric/state.py", line 9, in <module>
    from fabric.network import HostConnectionCache, ssh
  File "/usr/lib/python2.6/site-packages/fabric/network.py", line 24, in <module>
    import paramiko as ssh
  File "/usr/lib/python2.6/site-packages/paramiko/__init__.py", line 22, in <module>
    from paramiko.transport import SecurityOptions, Transport
  File "/usr/lib/python2.6/site-packages/paramiko/transport.py", line 89, in <module>
    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

When using the paramiko third-party library of python2.6.6 and python3.6 on centos6.9, the above error has been reported all the time

Python official recommendation str.format () to format strings, so using “{} / N”. Format (x) to process strings may encounter problems.

In Python 2 & gt; = 2.7 and python 3 & gt; = 3.1, str.format The positional parameter in () method can be omitted by default, but in Python 2 (& lt; 2.7) and python 3 (& lt; 3.1), you must display the specified (subscript starts from 0), otherwise “zero length field name in format” error will appear.

“{}CMD”.format( os.sep )# “{0} CMD”. Format can run normally in Python 2.7( os.sep )# in Python & lt; = 2.6 / 3.1, the specified subscript must be displayed, even if there is only one element.

Reference link: https://www.aliyun.com/jiaocheng/460757.html

Read More: