mitmdump无法与pymongo一起使用

时间:2018-07-30 10:19:11

标签: python python-3.x

我是python的新手,我试图使用mitmdump爬网应用程序并使用mongodb存储datus。但是...我在Google上找不到答案,也不知道该怎么办...我的Windows10平台。我认为Windows是否不支持

  

D:\ Users \ Administrator \ Desktop \ Python> mitmdump -s ScriptsTest.py   加载脚本ScriptsTest.py   插件错误:追溯(最近一次呼叫最近):     文件“ C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python36 \ site-   package \ mitmproxy \ addonmanager.py”,第42行,在safecall中       让     文件“ C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python36 \ site-   加载脚本中的“ packages \ mitmproxy \ addons \ script.py”行102       ctx.master.addons.register(ns)     文件“ C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python36 \ site-   包\ mitmproxy \ addonmanager.py”,第161行,在寄存器中       self.master.commands.collect_commands(a)     文件“ C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python36 \ site-   package_mitmproxy \ command.py“,第144行,在collect_commands中       self.add(o.command_path,o)     文件“ C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python36 \ site-   packages \ mitmproxy \ command.py”中的第151行       self.commands [path] =命令(self,path,func)     文件“ C:\ Users \ Administrator \ AppData \ Roaming \ Python \ Python36 \ site-   packages \ mitmproxy \ command.py”,第51行, init       sig = inspect.signature(self.func)     签名中的文件“ d:\ users \ administrator \ anaconda3 \ lib \ inspect.py”,行3033       返回Signature.from_callable(obj,follow_wrapped = follow_wrapped)     文件“ d:\ users \ administrator \ anaconda3 \ lib \ inspect.py”,第2783行,在   from_callable       follow_wrapper_chains =关注_包裹)     文件“ d:\ users \ administrator \ anaconda3 \ lib \ inspect.py”,第2183行,在   _signature_from_callable       引发TypeError('{!r}不是可调用对象'.format(obj))   TypeError:MongoClient(host = ['127.0.0.1:27017']、document_class=dict,   tz_aware = False,connect = True)不是可调用对象

这是我的脚本代码

import json
import pymongo
from mitmproxy import ctx

client = pymongo.MongoClient(host='127.0.0.1') 
db = client['igetget']
collection = db['books']


def response(flow):
    global collection
    url = 'https://dedao.igetget.com/v3/discover/bookList'
    if flow.request.url.startswith(url):
        text = flow.response.text
        data = json.loads(text)
        books = data.get('c').get('list')
        for book in books:
            data = {
                'title': book.get('operating_title'),
                'cover': book.get('cover'),
                'summary': book.get('other_share_summary'),
                'price': book.get('price')
            }
            ctx.log.info(str(data))
            collection.insert(data)

0 个答案:

没有答案