繁体   English   中英

mod_wsgi和zeromq错误(python)

[英]mod_wsgi and zeromq error (python)

我正在尝试制作一个在网络上运行的搜索引擎。 因此,我使用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]

在wsgi脚本中,显式添加依赖项的位置:

import site
site.addsitedir(path_to_zeromq)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM