File "E:\code\take.py", line 52, in take for s in fs.find({'packageName':doc['_id']}): AttributeError: 'GridFS' object has no attribute 'find' 请问各位朋友我python中报这个错误是什么原因,该如何解决呢?
下面是我的代码:
#!/bin/env/python
-*coding: utf-8 --
import pymongo
import pymongo
import gridfs
import sys
import copy
reload(sys)
sys.setdefaultencoding('utf-8')
import os
from gridfs import *
def take():
client = pymongo.MongoClient(host='192.168.213.225')
info_collection = client['up'].fdroid
shot_db2 = client['shots']
shot_db = client['os_shot']
#fs = gridfs.GridFS(shot_db2)
f = gridfs.GridFS(shot_db)
fs = gridfs.GridFS(shot_db2)
text=''
for doc in info_collection.find(
{
'interfaces': {'$exists': True},
# '_id':"apps.droidnotify",
# '_id':"com.appengine.paranoid_android.lost",
}
).limit(10).skip(0):
cnt=-1
dir_name = doc['_id']
try:
os.makedirs(dir_name)
except:
pass
with open(os.path.join(dir_name,'sequence.txt'),'w') as sequence_f:
for page in doc['interfaces']:
sequence_f.write(str(page['id'])+' '+str(page['parent'])+'\n')
cnt+=1
for node in page['viewnodes']:
if type(node['text'])==type(u'') and len(node['text'])>1 and node['height']!=0 and node['width']!=0:
text+=node['text'].lower().encode('utf-8')+' '
with open(os.path.join(dir_name, str(cnt)+'.txt'), 'w+b') as wf:
wf.write(text)
text=''
if doc['os']==1 :
for s in f.find({'packageName':doc['_id']}):
with open(os.path.join(dir_name, s.filename), 'w+b') as wf:
wf.write(s.read())
else:
for s in fs.find({'packageName':doc['_id']}):
with open(os.path.join(dir_name , s.filename), 'w+b' ) as wf:
wf.write(s.read())
#else:
# rf=fs
# for s in fs.find({'packageName':doc['_id']}):
# with open(os.path.join(dir_name, s.filename), 'w+b') as wf:
# wf.write(s.read())
take()