[AstroPy] Astropy in fails to import in Apache mod_wsgi Flask application

Erik Bray embray at stsci.edu
Mon Jul 14 17:27:13 EDT 2014


On 07/09/2014 04:45 PM, Leo Singer wrote:
> Hi,
>
> I have a Flask application that uses astropy, and I am trying to deploy it in Apache with mod_wsgi. Here's a minimal example app.wsgi file:
>
>      import astropy
>
>      from flask import Flask
>      app = Flask(__name__)
>
>      @app.route("/")
>      def hello():
>          return "Hello World!"
>
>      application = app
>
> It fails to import astropy because it cannot locate the Astropy config files. Here's the traceback from the Apache log file, error.log:
>
> /home/***/***/local/lib/python2.7/site-packages/astropy/config/configuration.py:680: ConfigurationMissingWarning: Configuration defaults will be used due to OSError:Could not find unix home directory to search for astropy config dir
>    warn(ConfigurationMissingWarning(msg))
> [client ***.***.***.***:*****] mod_wsgi (pid=*****): Target WSGI script '/home/***/***/var/ptf-instance/wsgi/ptftoo.wsgi' cannot be loaded as Python module.
> [client ***.***.***.***:*****] mod_wsgi (pid=*****): Exception occurred processing WSGI script '/home/***/***/var/ptf-instance/wsgi/ptftoo.wsgi'.
> [client ***.***.***.***:*****] Traceback (most recent call last):
> [client ***.***.***.***:*****]   File "/home/***/***/var/ptf-instance/wsgi/ptftoo.wsgi", line 4, in <module>
> [client ***.***.***.***:*****]     import astropy
> [client ***.***.***.***:*****]   File "/home/***/***/local/lib/python2.7/site-packages/astropy/__init__.py", line 268, in <module>
> [client ***.***.***.***:*****]     _initialize_astropy()
> [client ***.***.***.***:*****]   File "/home/***/***/local/lib/python2.7/site-packages/astropy/__init__.py", line 250, in _initialize_astropy
> [client ***.***.***.***:*****]     config.configuration.update_default_config(__package__, config_dir)
> [client ***.***.***.***:*****]   File "/home/***/***/local/lib/python2.7/site-packages/astropy/config/configuration.py", line 814, in update_default_config
> [client ***.***.***.***:*****]     if path.exists(cfgfn):
> [client ***.***.***.***:*****]   File "/home/***/***/lib/python2.7/genericpath.py", line 18, in exists
> [client ***.***.***.***:*****]     os.stat(path)
> [client ***.***.***.***:*****] TypeError: coercing to Unicode: need string or buffer, NoneType found
>
> It's running as a user without a home directory. How do I import astropy if I don't have a home directory?

Hi Leo,

Thanks for the update.  This is a known issue (it didn't come up in the context 
of a web server, though it was quickly realized "oh, this would also be a 
problem when trying to use Astropy in a web server!").  The issue is fixed in 
the current v0.4rc2 release candidate and should be fixed in the v0.4 final 
release as well.

If there is a strong need I can release a version of the v0.3.x series that 
fixes this, but updating to v0.4 should be considered preferable if at all possible.

The relevant issue is here:

https://github.com/astropy/astropy/pull/2689

Erik


(P.S. I think that issues like this--that is, problems that actually result in 
tracebacks and appear to be bugs in the astropy package itself, are best 
reported to the astropy issue tracker, rather than this mailing list which is 
more for general discussion about Astropy + Python in general).



More information about the AstroPy mailing list