I'm an newer in Python and just wrote some spiders using scrapy. Now i want to active my spider using http request like this: http://xxxxx.com/myspidername/args
I used nginx + uwsgi + django to call my scrapy spider.
Steps:
create&config django project
create scrapy project in the django project root and write my spider
start uwsgi: uwsgi -x django_socket.xml
call my spider in the django app's views.py
from django.http import HttpResponse from scrapy import cmdline def index(request, mid): cmd = "scrapy crawl myitem -a mid=" + mid cmdline.execute(cmd.split()) return HttpResponse("Hello, it work")
when i visit the http://myhost/myapp/index pointed to the index view, the nginx return error page and the error log shows "upstream prematurely closed connection while reading response header from upstream", and i can see the process uwsgi dispeared, but in the uwsgi's log i can see my spider run correctly.
How can i fix this error?
Is this way right? any other way to do what i want?