scrapy框架 mongodb 存在的问题,下面那个bug 如何解决?没有auth?我不知道这个anth怎么写

我在scrapy 中用mongodb 数据库的时候出现的问题

not authorized on Gov to execute command { insert: "Govdata", ordered:
true, documents: [ { plaintiff: "上诉人:陈汝香,夏张玲,朱春峰", openCourtAddr:
"第六法庭", _id: ObjectId('5a003fce6a91de158ab4'), openCourtDate:
1510038000000, courtName: "九江市中级人民法院" } ] } 2017-11-06 18:56:14
[scrapy.core.engine] INFO: Closing spider (finished) pipelines:

class MyspiderPipeline(object):    def __init__(self):
   host=settings['MONGODB_HOST']
   port=settings['MONGODB_PORT']
   dbname=settings['MONGODB_DBNAME']
   # dbname.auth("MONGODB_USER","MONGODB_PASSWD")
   client=pymongo.MongoClient(host=host,port=port)
   mdb=client[dbname]
   self.post=mdb[settings['MONGODB_DOCNAME']]    
  def process_item(self, item, spider):
   data=dict(item)
   self.post.insert(data)
   return item

settings

BOT_NAME="myspider"
SPIDER_MODULES=["myspider.spiders"]
NEWSPIDER_MODULE="myspider.spiders"
ITEM_PIPELINES = {
        'myspider.pipelines.MyspiderPipeline' : 300
        }
USER_AGENT ="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100

Safari/537.36"

MONGODB_HOST='127.0.0.1'
MONGODB_PORT=27017
MONGODB_DBNAME="Gov"
MONGODB_DOCNAME="Govdata"
MONGODB_USER="root"
MONGODB_PASSWD="123456"
阅读 2.1k
1 个回答

既然用了pymongo,就看一下pymongo怎么进行数据库链接密码验证的,看官方文档或者直接去源码找吧

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题