Ошибка mod_wsgi и zeromq (python) - PullRequest
       17

Ошибка mod_wsgi и zeromq (python)

0 голосов
/ 05 января 2012

Я пытаюсь сделать поисковик, работающий в сети. Поэтому я использовал mod_wsgi, чтобы получить запрос с веб-страницы с помощью python. Затем я использовал zeromq для отправки запроса в поисковую программу C ++.

Но проблема в том, что zeromq и mod_wsgi не работают вместе. Это определенно верно, что python может импортировать zmq (я проверял это), но когда он работает в Интернете, он показывает сообщение об ошибке (на самом деле журнал ошибок от Apache)

File "D:/wsgi_app/wsgi_app.py", line 2, in <module>, referer: http://localhost/
         import zmq, referer: http://localhost/

File "D:\\util\\Python27\\lib\\site-packages\\zmq\\__init__.py", line 35, in <module>, referer: http://localhost/
         from zmq.utils import initthreads # initialize threads, referer: http://localhost/

ImportError: DLL load failed: \xc1\xf6\xc1\xa4\xb5\xc8 \xb8\xf0\xb5\xe2\xc0\xbb \xc3\xa3\xc0\xbb \xbc\xf6 \xbe\xf8\xbd\xc0\xb4\xcf\xb4\xd9., referer: http://localhost/

Понятия не имею, почему wsgi не может импортировать zmq. Между прочим, нижеприведенный источник является полным кодом Python

from cgi import parse_qs, escape
import zmq
def application( # It accepts two arguments:
      # environ points to a dictionary containing CGI like environment variables
      # which is filled by the server for each received request from the client
      environ,
      # start_response is a callback function supplied by the server
      # which will be used to send the HTTP status and headers to the server
      start_response):

    # get a query from the webpage :)
   data = parse_qs(environ['QUERY_STRING'])

   query = data.get('query', [''])[0]
   query = escape(query) #prevent script injection

   context = zmq.Context()
   socket = context.socket(zmq.REQ)
   socket.connect ("tcp://localhost:5555") #connect to C++ search server database
   socket.send (query)

   # build the response body possibly using the environ dictionary
   response_body = 'The request method was %s' % environ['REQUEST_METHOD']

   # HTTP response code and message
   status = '200 OK'

   # These are HTTP headers expected by the client.
   # They must be wrapped as a list of tupled pairs:
   # [(Header name, Header value)].
   response_headers = [('Content-Type', 'text/plain'),
                       ('Content-Length', str(len(response_body)))]

   # Send them to the server using the supplied function
   start_response(status, response_headers)

   # Return the response body.
   # Notice it is wrapped in a list although it could be any iterable.
   return [response_body]

1 Ответ

0 голосов
/ 05 января 2012

В вашем скрипте wsgi явно добавьте расположение ваших зависимостей:

import site
site.addsitedir(path_to_zeromq)
...