1

I'm trying to get a Python Flask application running under Apache 2.4.7 with mod_wsgi. Its main purpose is to build a graph of people and their interests, with connections between them (e.g. if A and B are both interested in PHP, there will be a A <-> PHP <-> B link).

I've compiled Graphviz manually as the Ubuntu package disables GTS and the application needs that feature. The compile options I've used are: --disable-static --with-x --with-gts --disable-ruby --disable-tcl.

I've installed pygraphviz using: sudo pip install pygraphviz. I'm using Python 2.7.6 on Ubuntu 14.04.

The basic code which seems to be causing the problem is:

import pygraphviz as pgv 
graph = pgv.AGraph(overlap = 'false', name = name)
# Add nodes
graph.layout(prog = 'neato')

This runs fine on the command line, but when I run it under Apache I get an Internal Server Error and the following traceback in the error log:

[Mon Jan 12 13:45:38.228420 2015] [:error] [pid 19500:tid 140471782790912] Traceback (most recent call last):
[Mon Jan 12 13:45:38.228427 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
[Mon Jan 12 13:45:38.228434 2015] [:error] [pid 19500:tid 140471782790912]     response = self.full_dispatch_request()
[Mon Jan 12 13:45:38.228459 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
[Mon Jan 12 13:45:38.228465 2015] [:error] [pid 19500:tid 140471782790912]     rv = self.handle_user_exception(e)
[Mon Jan 12 13:45:38.228471 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
[Mon Jan 12 13:45:38.228476 2015] [:error] [pid 19500:tid 140471782790912]     reraise(exc_type, exc_value, tb)
[Mon Jan 12 13:45:38.228481 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
[Mon Jan 12 13:45:38.228489 2015] [:error] [pid 19500:tid 140471782790912]     rv = self.dispatch_request()
[Mon Jan 12 13:45:38.228594 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
[Mon Jan 12 13:45:38.228603 2015] [:error] [pid 19500:tid 140471782790912]     return self.view_functions[rule.endpoint](**req.view_args)
[Mon Jan 12 13:45:38.228609 2015] [:error] [pid 19500:tid 140471782790912]   File "/home/paul/supervisor-finder/flask/supervisorfinder.py", line 154, in show_person
[Mon Jan 12 13:45:38.228614 2015] [:error] [pid 19500:tid 140471782790912]     graph = build_graph(graph_name, results, topics)
[Mon Jan 12 13:45:38.228659 2015] [:error] [pid 19500:tid 140471782790912]   File "/home/paul/supervisor-finder/flask/supervisorfinder.py", line 124, in build_graph
[Mon Jan 12 13:45:38.228668 2015] [:error] [pid 19500:tid 140471782790912]     graph.layout(prog = 'neato')
[Mon Jan 12 13:45:38.228674 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/lib/pymodules/python2.7/pygraphviz/agraph.py", line 1305, in layout
[Mon Jan 12 13:45:38.228679 2015] [:error] [pid 19500:tid 140471782790912]     data=self._run_prog(prog,' '.join([args,"-T",fmt]))
[Mon Jan 12 13:45:38.228684 2015] [:error] [pid 19500:tid 140471782790912]   File "/usr/lib/pymodules/python2.7/pygraphviz/agraph.py", line 1278, in _run_prog
[Mon Jan 12 13:45:38.228728 2015] [:error] [pid 19500:tid 140471782790912]     raise IOError("".join(errors))
[Mon Jan 12 13:45:38.228736 2015] [:error] [pid 19500:tid 140471782790912] IOError

My WSGI configuration file is:

import sys
import logging

sys.path.insert(0, '/home/paul/supervisor-finder/flask')
logging.basicConfig(stream=sys.stderr)

from supervisorfinder import app as application

I thought at first it might be the same problem as this question: PyGraphViz agraph.layout() throws I0 error but I've checked the source of agraph.py and it is not calling a _get_prog function.

Can anyone suggest what might be wrong? I'm fairly new to Python (usually I use C-style languages such as Perl and PHP) so it's possible I'm making an 'obvious' error.

Community
  • 1
  • 1
pwaring
  • 3,032
  • 8
  • 30
  • 46
  • It would be helpful to see the actual error that _run_prog() is generating. It could be that it works for you as a regular user but the Apache environment doesn't have the correct path to the graphivz binary programs (dot, neato, and friends). – Aric Jan 13 '15 at 04:46
  • I'm not sure what you mean by 'the actual error that _run_prog is generating' - the above traceback is the only message in the error log. – pwaring Jan 13 '15 at 09:39
  • I was thinking that `raise IOError("".join(errors))` would have more output (the `errors` variable). Maybe try running your code as the Apache user? It could be a path or permissions problem for that user. – Aric Jan 13 '15 at 14:08

0 Answers0