Scrapy安装完成后shell报错:def write(self, data, async=False): SyntaxError: invalid syntax

错误内容

C:\Users\gismi>scrapy shell https://www.baidu.com/?tn=93380420_hao_pg
2018-07-15 16:08:27 [scrapy.utils.log] INFO: Scrapy 1.5.1 started (bot: scrapybot)
2018-07-15 16:08:27 [scrapy.utils.log] INFO: Versions: lxml 4.2.3.0, libxml2 2.9.7, cssselect 1.0.3, parsel 1.5.0, w3lib 1.19.0, Twisted 18.7.0, Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)], pyOpenSSL 18.0.0 (OpenSSL 1.1.0h  27 Mar 2018), cryptography 2.2.2, Platform Windows-10-10.0.17134-SP0
2018-07-15 16:08:27 [scrapy.crawler] INFO: Overridden settings: {'DUPEFILTER_CLASS': 'scrapy.dupefilters.BaseDupeFilter', 'LOGSTATS_INTERVAL': 0}
Traceback (most recent call last):
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\gismi\AppData\Local\Programs\Python\Python37\Scripts\scrapy.exe\__main__.py", line 9, in 
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\cmdline.py", line 150, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\cmdline.py", line 90, in _run_print_help
    func(*a, **kw)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\cmdline.py", line 157, in _run_command
    cmd.run(args, opts)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\commands\shell.py", line 65, in run
    crawler = self.crawler_process._create_crawler(spidercls)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\crawler.py", line 203, in _create_crawler
    return Crawler(spidercls, self.settings)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\crawler.py", line 55, in __init__
    self.extensions = ExtensionManager.from_crawler(self)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\middleware.py", line 58, in from_crawler
    return cls.from_settings(crawler.settings, crawler)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\middleware.py", line 34, in from_settings
    mwcls = load_object(clspath)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\utils\misc.py", line 44, in load_object
    mod = import_module(module)
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 967, in _find_and_load_unlocked
  File "", line 677, in _load_unlocked
  File "", line 728, in exec_module
  File "", line 219, in _call_with_frames_removed
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\scrapy\extensions\telnet.py", line 12, in 
    from twisted.conch import manhole, telnet
  File "c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\twisted\conch\manhole.py", line 154
    def write(self, data, async=False):
                              ^
SyntaxError: invalid syntax

我就很纳闷了,难道是安装失败了吗,然后又试了一下:scrapy startproject test
显示成功创建,很烦,莫名的错误,度娘一圈没找到什么结果,死马当活马医,打开c:\users\gismi\appdata\local\programs\python\python37\lib\site-packages\twisted\conch\manhole.py看了一眼,发现不对,如下:


图片.png

为什么这个async的字体有颜色,跟其他变量颜色不一样,难道他是什么关键字?
我又去度娘scrapy async发现果然,async def用来标记一个异步模块。这可一脸懵逼的我在把async改成了async1,颜色变了


图片.png

试一试,不行再改回来,嘿,这个错误没有了,当然还有其他错,不过也都是应为这个变量名的问题,全部更换成async1后就正常运行了
坑啊,这是什么鬼呦!!!!!

你可能感兴趣的:(Scrapy安装完成后shell报错:def write(self, data, async=False): SyntaxError: invalid syntax)