Skip to content

scrapy: exceptions.ImportError: cannot import name to_native_str

Shuang0420 edited this page Jul 5, 2016 · 1 revision

错误

suredeMBP-2:splash_example Shuang$ scrapy crawl test
2016-07-05 17:18:50 log.py[line:127] INFO Scrapy 1.0.4 started (bot: splash_example)
2016-07-05 17:18:50 [scrapy] INFO: Scrapy 1.0.4 started (bot: splash_example)
2016-07-05 17:18:50 log.py[line:130] INFO Optional features available: ssl, http11, boto
2016-07-05 17:18:50 [scrapy] INFO: Optional features available: ssl, http11, boto
2016-07-05 17:18:50 log.py[line:133] INFO Overridden settings: {'NEWSPIDER_MODULE': 'splash_example.spiders', 'DUPEFILTER_CLASS': 'scrapy_splash.SplashAwareDupeFilter', 'SPIDER_MODULES': ['splash_example.spiders'], 'BOT_NAME': 'splash_example', 'USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36', 'HTTPCACHE_STORAGE': 'scrapy_splash.SplashAwareFSCacheStorage'}
2016-07-05 17:18:50 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'splash_example.spiders', 'DUPEFILTER_CLASS': 'scrapy_splash.SplashAwareDupeFilter', 'SPIDER_MODULES': ['splash_example.spiders'], 'BOT_NAME': 'splash_example', 'USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36', 'HTTPCACHE_STORAGE': 'scrapy_splash.SplashAwareFSCacheStorage'}
2016-07-05 17:18:50 middleware.py[line:51] INFO Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState
2016-07-05 17:18:50 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState
2016-07-05 17:18:50 provider.py[line:282] DEBUG Using access key found in environment variable.
2016-07-05 17:18:50 [boto] DEBUG: Using access key found in environment variable.
2016-07-05 17:18:50 provider.py[line:309] DEBUG Using secret key found in environment variable.
2016-07-05 17:18:50 [boto] DEBUG: Using secret key found in environment variable.
Unhandled error in Deferred:
2016-07-05 17:18:50 _legacy.py[line:154] CRITICAL Unhandled error in Deferred:
2016-07-05 17:18:50 [twisted] CRITICAL: Unhandled error in Deferred:


Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 150, in _run_command
    cmd.run(args, opts)
  File "/usr/local/lib/python2.7/site-packages/scrapy/commands/crawl.py", line 57, in run
    self.crawler_process.crawl(spname, **opts.spargs)
  File "/usr/local/lib/python2.7/site-packages/scrapy/crawler.py", line 153, in crawl
    d = crawler.crawl(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1274, in unwindGenerator
    return _inlineCallbacks(None, gen, Deferred())
--- <exception caught here> ---
  File "/usr/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1128, in _inlineCallbacks
    result = g.send(result)
  File "/usr/local/lib/python2.7/site-packages/scrapy/crawler.py", line 71, in crawl
    self.engine = self._create_engine()
  File "/usr/local/lib/python2.7/site-packages/scrapy/crawler.py", line 83, in _create_engine
    return ExecutionEngine(self, lambda _: self.stop())
  File "/usr/local/lib/python2.7/site-packages/scrapy/core/engine.py", line 68, in __init__
    self.downloader = downloader_cls(crawler)
  File "/usr/local/lib/python2.7/site-packages/scrapy/core/downloader/__init__.py", line 69, in __init__
    self.middleware = DownloaderMiddlewareManager.from_crawler(crawler)
  File "/usr/local/lib/python2.7/site-packages/scrapy/middleware.py", line 56, in from_crawler
    return cls.from_settings(crawler.settings, crawler)
  File "/usr/local/lib/python2.7/site-packages/scrapy/middleware.py", line 32, in from_settings
    mwcls = load_object(clspath)
  File "/usr/local/lib/python2.7/site-packages/scrapy/utils/misc.py", line 44, in load_object
    mod = import_module(module)
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/site-packages/scrapy_splash/__init__.py", line 4, in <module>
    from .middleware import (
  File "/usr/local/lib/python2.7/site-packages/scrapy_splash/middleware.py", line 17, in <module>
    from scrapy.utils.python import to_native_str
exceptions.ImportError: cannot import name to_native_str

解决

更新scrapy

sudo pip --default-timeout=100 install -U scrape

[[TOC]]

Clone this wiki locally