鍍金池/ 問答/Python  數(shù)據(jù)庫/ scrapy框架 mongodb 存在的問題,下面那個bug 如何解決?

scrapy框架 mongodb 存在的問題,下面那個bug 如何解決?沒有auth?我不知道這個anth怎么寫

我在scrapy 中用mongodb 數(shù)據(jù)庫的時候出現(xiàn)的問題

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"
回答
編輯回答
久愛她

既然用了pymongo,就看一下pymongo怎么進行數(shù)據(jù)庫鏈接密碼驗證的,看官方文檔或者直接去源碼找吧

2018年2月13日 15:24