0

求助: scrapyd 不能修改 scrapy 的 settings.py 设置

 2 years ago
source link: https://www.v2ex.com/t/844499
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  Python

求助: scrapyd 不能修改 scrapy 的 settings.py 设置

  JarvenI · 14 小时 12 分钟前 · 184 次点击

我是用的 scrapyd+python+scrapyd-api+scrapyd-client 形式,每次运行时启动 scrapyd ,部署项目,部分代码如下

    if subprocess.call('scrapyd') != 0:
        logger.error('启动 scrapyd 失败')

    if subprocess.call('scrapyd-deploy 项目名 -p 项目名') != 0:
        logger.error('启动 scrapyd-deploy 失败')
    
    setting = {
    'MYSQL_PASSWD': '123',
	}

    while True:
        if scrapyd.list_spiders('项目名'):
            jobs = scrapyd.list_jobs(PROJECT)
            if not (jobs['pending'] or jobs['running']):
                scrapyd.schedule(PROJECT, 'spider_name', settings=setting)

试了好几种方式,最后下载个 curl 发现,不能通过

curl http://localhost:6800/schedule.json -d project=项目名 -d spider=爬虫名 -d setting=MYSQL_PASSWD=123

方式来修改 setting 里的设置。 按照网上搜索的,也尝试了

curl http://localhost:6800/schedule.json -d project=项目 -d spider=爬虫 -d MYSQL_PASSWD=123

第 1 条附言  ·  10 小时 27 分钟前

找到解决办法了,用环境变量来替代 setting.py 里的变量了

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK