为什么名称解析错误没有被 EXCEPT 捕获?另外,我怎样才能获取错误文本并将其也扔到记录器设施中?谢谢你。
logging.basicConfig(filename = "{}.log".format(sys.argv[0]), level=logging.DEBUG)
def simpleLogger(something):
try :
something
logging.info("Iteration fine")
except :
logging.warning("Something bad happened!")
def doSometh():
conn = psycopg2.connect(host = "1x18.249.21" , user = "tima", dbname = "tima")
curr = conn.cursor()
sql = "select * from app_catalog;"
curr.execute(sql)
print curr.fetchall()
def main():
simpleLogger(doSometh())
if __name__ == '__main__':
sys.exit(main())
这是产生的错误:
conn = psycopg2.connect(host = "172.x18.249.21" , user = "tima", dbname = "tima")
File "/apps/appeng/python-2.7.3/lib/python2.7/site-packages/psycopg2/__init__.py", line 179, in connect connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not translate host name "172.x18.249.21" to address: Name or service not known