[python] 修复读取 utf-8 BOM 编码的配置文件时出现的 ConfigParser.MissingSectionHeaderError: File contains no section headers 错误

当使用 ConfigParser 读取 utf-8 BOM 编码的配置文件时,会出现如下类似错误:

ConfigParser.MissingSectionHeaderError: File contains no section headers.
File: settings.ini, line: 1
'\xef\xbb\xbf[General]\n'

解决办法就是先将文件内容读出来,然后转码,然后再读取转码后的配置信息:

import ConfigParser
from StringIO import StringIO

conf = ConfigParser.RawConfigParser()
with open('settings.ini', 'rb') as f:
    content = f.read().decode('utf-8-sig').encode('utf8 ...
more ...

[linux]无法启动 rabbitmq-server,出现 timeout 错误

Date Category linux Tags linux

上次安装 rabbitmq 时,有台服务器上 service rabbitmq-server start 总是起不来。 错误日志里出现如下错误:

ERROR: epmd error for host "yourhostname": timeout (xxxxx)

解决办法就是, 修改 /etc/hosts 将本机的 hostname 加进去:

127.0.0.1    yourhostname

参考

more ...

[django]修复 "TypeError: delete() got an unexpected keyword argument 'using'"

调用 delete 方法时,下面的代码会导致出现标题中的错误:

Foo.objects.filter(name='foo').delete(using='writedb')

原因是因为只有单个查询结果对象的 delete 方法拥有 using 参数, 而查询结果集对象的 delete 方法没有 using 关键字参数:

foos = Foo.objects.filter(name='foo')
for foo in foos:
    foos.delete(using='writedb')
more ...