MissingSectionHeaderError:文件不包含节标题

Nen*_*vic 15 python virtualenv

我正在尝试根据本手册构建collective.simserver:

http://plone.org/products/collective.simserver
Run Code Online (Sandbox Code Playgroud)

经过一些修改:

instead of: virtualenv --python=bin/python2.7 simserver/
I am using: virtualenv --python=myVirtualEnv/bin/python simserver
Run Code Online (Sandbox Code Playgroud)

(因为如果我按照例子它将无法工作)

我设法达到了这一点:

myVirtualEnv/bin/python bootstrap.py
Run Code Online (Sandbox Code Playgroud)

然后它与这个错误信息分开:

    Mint-AMD64 nenad # myVirtualEnv/bin/python bootstrap.py
While:
  Initializing.

An internal error occurred due to a bug in either zc.buildout or in a
recipe being used:
Traceback (most recent call last):
  File "/tmp/tmpLiHZgo/zc.buildout-1.6.3-py2.6.egg/zc/buildout/buildout.py", line 1851, in main
    command)
  File "/tmp/tmpLiHZgo/zc.buildout-1.6.3-py2.6.egg/zc/buildout/buildout.py", line 203, in __init__
    data['buildout'].copy(), override, set()))
  File "/tmp/tmpLiHZgo/zc.buildout-1.6.3-py2.6.egg/zc/buildout/buildout.py", line 1465, in _open
    parser.readfp(fp)
  File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp
    self._read(fp, filename)
  File "/usr/lib/python2.6/ConfigParser.py", line 482, in _read
    raise MissingSectionHeaderError(fpname, lineno, line)
MissingSectionHeaderError: File contains no section headers.
file: /home/nenad/buildout.cfg, line: 4
'<!DOCTYPE html>\n'
Mint-AMD64 nenad # 
Run Code Online (Sandbox Code Playgroud)

可能有什么问题?

此致,Nenad

pit*_*all 20

对我来说,我看到这个错误是因为我错误地假设 的 API.read_file()接受文件路径,但它只接受文件句柄。


Ali*_* SH 9

我想我迟到的答案,但它发生在我保存Config文件时UTF-8 尝试保存文件为ANSI.

  • 适用于 python 3.5 的没有 BOM 的 UTF-8 (2认同)

yat*_*atu 9

此错误很可能是因为配置文件中的部分缺少标头(或者指定不正确)。请参阅configparser文档以了解配置文件必须具有的格式。

配置文件由几部分组成,前面必须有[header],例如:

[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes

[bitbucket.org]
User = hg

[topsecret.server.com]
Port = 50022
ForwardX11 = no
Run Code Online (Sandbox Code Playgroud)

配置文件中的每个部分都将包含由字符串(=:默认情况下)分隔的键/值对。每个部分的标题必须采用以下格式,任何不同的内容[header]都会产生configparser.MissingSectionHeaderError.


Syn*_*nck 7

配置文件中没有节头.

配置文件由部分组成,由[section]标头引导,后跟name:value条目.

Docs CofigParser python模块

  • 我认为这应该是一个评论. (3认同)