无法部署到ScrapingHub不存在的SyntaxError:语法无效

时间:2019-02-27 21:46:49

标签: python web-scraping scrapy scrapy-spider scrapinghub

我有一个Scrapy Spider,如果我打电话给我,它可以完美运行:scrapy crawl。 当我尝试将其部署到ScrapingHub.com时,会引发无法修复的SyntaxError。我不知道发生了什么事。 我的代码中没有语法错误。

这是我的部署输出:

    API key is OK, you are logged in now.
omars-MacBook-Pro:airbnb omaromeiri$ shub deploy 377112
Saving project 377112 as default target. You can deploy to it via 'shub deploy' from now on
Saved to /Users/omaromeiri/Documents/Python/Scrapy/airbnb/scrapinghub.yml.
Packing version 1.0
Deploying to Scrapy Cloud project "377112"
Deploy log last 30 lines:
    _run(args, settings)
  File "/usr/local/lib/python2.7/site-packages/sh_scrapy/crawl.py", line 103, in _run
    _run_scrapy(args, settings)
  File "/usr/local/lib/python2.7/site-packages/sh_scrapy/crawl.py", line 111, in _run_scrapy
    execute(settings=settings)
  File "/usr/local/lib/python2.7/site-packages/scrapy/cmdline.py", line 148, in execute
    cmd.crawler_process = CrawlerProcess(settings)
  File "/usr/local/lib/python2.7/site-packages/scrapy/crawler.py", line 243, in __init__
    super(CrawlerProcess, self).__init__(settings)
  File "/usr/local/lib/python2.7/site-packages/scrapy/crawler.py", line 134, in __init__
    self.spider_loader = _get_spider_loader(settings)
  File "/usr/local/lib/python2.7/site-packages/scrapy/crawler.py", line 330, in _get_spider_loader
    return loader_cls.from_settings(settings.frozencopy())
  File "/usr/local/lib/python2.7/site-packages/scrapy/spiderloader.py", line 61, in from_settings
    return cls(settings)
  File "/usr/local/lib/python2.7/site-packages/scrapy/spiderloader.py", line 25, in __init__
    self._load_all_spiders()
  File "/usr/local/lib/python2.7/site-packages/scrapy/spiderloader.py", line 47, in _load_all_spiders
    for module in walk_modules(name):
  File "/usr/local/lib/python2.7/site-packages/scrapy/utils/misc.py", line 71, in walk_modules
    submod = import_module(fullpath)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/app/__main__.egg/airbnb/spiders/airbnb_spider.py", line 28
    'Coordinates': f"{accomodation.get('listing').get('lat')},{accomodation.get('listing').get('lng')}",
                                                                                                      ^
SyntaxError: invalid syntax
{"message": "shub-image-info exit code: 1", "details": null, "error": "image_info_error"}

{"status": "error", "message": "Internal error"}
Deploy log location: /var/folders/3f/yyvy83n55tv66fdw10cbb4d80000gn/T/shub_deploy_rx_i_0wr.log
Error: Deploy failed: b'{"status": "error", "message": "Internal error"}'

2 个答案:

答案 0 :(得分:2)

您正在使用Python 3.6+语法,但已部署到Python 2.7环境。

答案 1 :(得分:0)

要添加Daniel Roseman's answer之外的解决方案,您需要在ScrapingHub配置中指定Python 3环境。运行shub命令后,您的项目中应该有一个scrapinghub.yml文件。使用目标环境进行更新:

project: 123456 

stacks:
    default: scrapy:1.6-py3

用您自己的项目编号代替。并且,如果您需要在Python 3环境中使用特定版本的Scrapy,请参阅文档:https://support.scrapinghub.com/support/solutions/articles/22000200387-deploying-python-3-spiders-to-scrapy-cloud