mongoDB官网中Storing Log Data的python示例代码有误,

版权声明:https://blog.csdn.net/muzizongheng, .net/web/医疗技术的个人分享 https://blog.csdn.net/muzizongheng/article/details/85164206

如题, 

在这篇文章中的python代码中, 构造一个记录的代码如下:

>>> event = {

... _id: bson.ObjectId(),

... host: "127.0.0.1",

... time: datetime(2000,10,10,20,55,36),

... path: "/apache_pb.gif",

... referer: "[http://www.example.com/start.html](http://www.example.com/start.html)",

... user_agent: "Mozilla/4.08 [en] (Win98; I ;Nav)"

...}

编译错误, python的字典的初始化时, key必须加单引号‘’。

正确如下:

event = {

    '_id': bson.ObjectId(),

    'host': "127.0.0.1",

    'time':  datetime(2000,10,10,20,55,36),

    'path': "/apache_pb.gif",

    'referer': "[http://www.example.com/start.html](http://www.example.com/start.html)" ,

    'user_agent': "Mozilla/4.08 [en] (Win98; I ;Nav)"

}

猜你喜欢

转载自blog.csdn.net/muzizongheng/article/details/85164206
今日推荐