从pythonanywh上的脚本运行时出现内部服务器错误

2024-04-24 04:00:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了一个奇怪的问题,关于Python岛上的一只破蜘蛛。在

我正在运行一些这种蜘蛛。我通过调度任务调用python脚本来启动它们,检查spider的一个实例是否已经在运行,如果没有,则运行spider。脚本如下所示:

from tendo import singleton
me = singleton.SingleInstance()

import os
class cd:
    def __init__(self, newPath):
        self.newPath = os.path.expanduser(newPath)

    def __enter__(self):
        self.savedPath = os.getcwd()
        os.chdir(self.newPath)

    def __exit__(self, etype, value, traceback):
        os.chdir(self.savedPath)


from scrapy.crawler import CrawlerProcess
from scrapy.utils.project import get_project_settings

with cd("/home/username/notebooksbilliger"):
    process = CrawlerProcess(get_project_settings())
    process.crawl('notebooksbilliger')
    process.start()

对于大多数spider,这个脚本运行得很好,但是对于一个特定的spider,当spider启动时,它总是抛出500个内部服务器错误,如下所示,这会导致spider中止:

^{pr2}$

如果我在shell中简单地调用“scrapy crawl notebooks billiger”来运行蜘蛛,那么一切都很好。在

有人知道为什么会发生这种情况吗?或者能告诉我一种方法来找出为什么会发生这种情况吗?在


Tags: fromimportselfproject脚本osdefcd