Forums

error AttributeError: 'list' object has no attribute 'abspath'

I had a django application on my own server and I moved it to pythonanywhere. my test files say the application is running but when I try to start it from the site http://capsence.pythonanywhere.com/testbench/ I get Unhandled Exception and the error message below...

I have no clue where look for this error...

Any ideas.

2014-04-02 11:33:44,275 :Traceback (most recent call last):
2014-04-02 11:33:44,275 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-04-02 11:33:44,275 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-04-02 11:33:44,276 :  File "/usr/lib/python2.7/logging/__init__.py", line 1183, in exception
2014-04-02 11:33:44,276 :    self.error(msg, *args, **kwargs)
2014-04-02 11:33:44,276 :  File "/usr/lib/python2.7/logging/__init__.py", line 1176, in error
2014-04-02 11:33:44,276 :    self._log(ERROR, msg, args, **kwargs)
2014-04-02 11:33:44,276 :  File "/usr/lib/python2.7/logging/__init__.py", line 1268, in _log
2014-04-02 11:33:44,277 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-04-02 11:33:44,277 :  File "/usr/lib/python2.7/logging/__init__.py", line 1242, in makeRecord
2014-04-02 11:33:44,277 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-04-02 11:33:44,277 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-04-02 11:33:44,278 :    self.threadName = threading.current_thread().name
2014-04-02 11:33:44,278 :  File "/usr/lib/python2.7/threading.py", line 1158, in currentThread
2014-04-02 11:33:44,278 :    return _active[_get_ident()]
2014-04-02 11:33:44,278 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-04-02 11:33:44,278 :    app_iterator = self.app(environ, start_response)
2014-04-02 11:33:44,279 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-04-02 11:33:44,279 :    raise e
2014-04-02 11:33:44,279 :AttributeError: 'list' object has no attribute 'abspath'
2014-04-02 11:33:48,256 :Traceback (most recent call last):
2014-04-02 11:33:48,257 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-04-02 11:33:48,258 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-04-02 11:33:48,258 :  File "/usr/lib/python2.7/logging/__init__.py", line 1183, in exception
2014-04-02 11:33:48,258 :    self.error(msg, *args, **kwargs)
2014-04-02 11:33:48,258 :  File "/usr/lib/python2.7/logging/__init__.py", line 1176, in error
2014-04-02 11:33:48,259 :    self._log(ERROR, msg, args, **kwargs)
2014-04-02 11:33:48,259 :  File "/usr/lib/python2.7/logging/__init__.py", line 1268, in _log
2014-04-02 11:33:48,259 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-04-02 11:33:48,259 :  File "/usr/lib/python2.7/logging/__init__.py", line 1242, in makeRecord
2014-04-02 11:33:48,260 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-04-02 11:33:48,260 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-04-02 11:33:48,260 :    self.threadName = threading.current_thread().name
2014-04-02 11:33:48,260 :  File "/usr/lib/python2.7/threading.py", line 1158, in currentThread
2014-04-02 11:33:48,260 :    return _active[_get_ident()]
2014-04-02 11:33:48,260 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-04-02 11:33:48,261 :    app_iterator = self.app(environ, start_response)
2014-04-02 11:33:48,261 :  File "/bin/user_wsgi_wrapper.py", line 73, in import_error_application
2014-04-02 11:33:48,261 :    raise e
2014-04-02 11:33:48,261 :AttributeError: 'list' object has no attribute 'abspath'

That looks like there's an error in your WSGI file. Could you post it here?

# This file contains the WSGI configuration required to serve up your
# web application at http://capsence.pythonanywhere.com/
# It works by setting the variable 'application' to a WSGI handler of some
# description.
#
# Below are templates for Django and Flask.  You should update the file
# appropriately for the web framework you're using, and then
# click the 'Reload /yourdomain.com/' button on the 'Web' tab to make your site
# live.


# +++++++++++ CUSTOM WSGI +++++++++++
# If you have a WSGI file that you want to serve using PythonAnywhere, perhaps
# in your home directory under version control, then use something like this:
#
#import os
#import sys
#
#path = '/home/capsence/capsence/metisq/httpapi'
#if path not in sys.path:
#    sys.path.append(path)
#
#from django import application

#capsence.pythonanywhere.com
# +++++++++++ DJANGO +++++++++++
# To use your own django app use code like this:
import os
import sys
#
## assuming your django settings file is at '/home/capsence/mysite/settings.py'
path = '/home/capsence/capsence/metisq/httpapi'
sys.path.append(path)
sys.path.extend ([
    sys.path.abspath (sys.path.join (sys.path.dirname (__file__), '..')),
    sys.path.abspath (sys.path.dirname (__file__))
])

if path not in sys.path:
    sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'httpapi.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

OK, there's the problem:

sys.path.extend ([
    sys.path.abspath (sys.path.join (sys.path.dirname (__file__), '..')),
    sys.path.abspath (sys.path.dirname (__file__))
])

I think you mean os.path.abspath instead of sys.path.abspath.

Ok... loads of other errors... but a step further.

What are the errors you're getting now?

I think it is still related to path... it is complaining no module httpapi.urls urls is in rest http://capsence.pythonanywhere.com/rest/version/

2014-04-02 16:49:17,117 :Internal Server Error: /rest/version/
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 101, in get_response
    request.path_info)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 250, in resolve
    for pattern in self.url_patterns:
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 279, in _get_url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named httpapi.urls
2014-04-02 16:49:18,137 :Traceback (most recent call last):
2014-04-02 16:49:18,137 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-04-02 16:49:18,138 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-04-02 16:49:18,138 :  File "/usr/lib/python2.7/logging/__init__.py", line 1183, in exception
2014-04-02 16:49:18,138 :    self.error(msg, *args, **kwargs)
2014-04-02 16:49:18,138 :  File "/usr/lib/python2.7/logging/__init__.py", line 1176, in error
2014-04-02 16:49:18,139 :    self._log(ERROR, msg, args, **kwargs)
2014-04-02 16:49:18,139 :  File "/usr/lib/python2.7/logging/__init__.py", line 1268, in _log
2014-04-02 16:49:18,139 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-04-02 16:49:18,139 :  File "/usr/lib/python2.7/logging/__init__.py", line 1242, in makeRecord
2014-04-02 16:49:18,139 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-04-02 16:49:18,140 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-04-02 16:49:18,140 :    self.threadName = threading.current_thread().name
2014-04-02 16:49:18,140 :  File "/usr/lib/python2.7/threading.py", line 1158, in currentThread
2014-04-02 16:49:18,140 :    return _active[_get_ident()]
2014-04-02 16:49:18,140 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-04-02 16:49:18,141 :    app_iterator = self.app(environ, start_response)
2014-04-02 16:49:18,141 :  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
2014-04-02 16:49:18,141 :    response = self.get_response(request)
2014-04-02 16:49:18,141 :  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 169, in get_response
2014-04-02 16:49:18,141 :    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2014-04-02 16:49:18,141 :  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
2014-04-02 16:49:18,142 :    if resolver.urlconf_module is None:
2014-04-02 16:49:18,142 :  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
2014-04-02 16:49:18,142 :    self._urlconf_module = import_module(self.urlconf_name)
2014-04-02 16:49:18,142 :  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
2014-04-02 16:49:18,142 :    __import__(name)
2014-04-02 16:49:18,142 :ImportError: No module named httpapi.urls
2014-04-02 16:49:18,827 :Internal Server Error: /favicon.ico
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 89, in get_response
    response = middleware_method(request)
  File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py", line 67, in process_request
    if (not _is_valid_path(request.path_info, urlconf) and
  File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py", line 154, in _is_valid_path
    urlresolvers.resolve(path, urlconf)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 342, in resolve
    return get_resolver(urlconf).resolve(path)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 250, in resolve
    for pattern in self.url_patterns:
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 279, in _get_url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
ImportError: No module named httpapi.urls
2014-04-02 16:49:18,833 :Traceback (most recent call last):
2014-04-02 16:49:18,833 :  File "/bin/user_wsgi_wrapper.py", line 67, in __call__
2014-04-02 16:49:18,833 :    self.error_log_file.logger.exception("Error running WSGI application")
2014-04-02 16:49:18,833 :  File "/usr/lib/python2.7/logging/__init__.py", line 1183, in exception
2014-04-02 16:49:18,834 :    self.error(msg, *args, **kwargs)
2014-04-02 16:49:18,834 :  File "/usr/lib/python2.7/logging/__init__.py", line 1176, in error
2014-04-02 16:49:18,834 :    self._log(ERROR, msg, args, **kwargs)
2014-04-02 16:49:18,834 :  File "/usr/lib/python2.7/logging/__init__.py", line 1268, in _log
2014-04-02 16:49:18,835 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2014-04-02 16:49:18,835 :  File "/usr/lib/python2.7/logging/__init__.py", line 1242, in makeRecord
2014-04-02 16:49:18,835 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2014-04-02 16:49:18,835 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2014-04-02 16:49:18,835 :    self.threadName = threading.current_thread().name
2014-04-02 16:49:18,836 :  File "/usr/lib/python2.7/threading.py", line 1158, in currentThread
2014-04-02 16:49:18,836 :    return _active[_get_ident()]
2014-04-02 16:49:18,836 :  File "/bin/user_wsgi_wrapper.py", line 59, in __call__
2014-04-02 16:49:18,836 :    app_iterator = self.app(environ, start_response)
2014-04-02 16:49:18,836 :  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
2014-04-02 16:49:18,837 :    response = self.get_response(request)
2014-04-02 16:49:18,837 :  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 169, in get_response
2014-04-02 16:49:18,837 :    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
2014-04-02 16:49:18,837 :  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
2014-04-02 16:49:18,837 :    if resolver.urlconf_module is None:
2014-04-02 16:49:18,837 :  File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
2014-04-02 16:49:18,838 :    self._urlconf_module = import_module(self.urlconf_name)
2014-04-02 16:49:18,838 :  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
2014-04-02 16:49:18,838 :    __import__(name)
2014-04-02 16:49:18,838 :ImportError: No module named httpapi.urls

Without looking at your files I can't be sure, but it looks like you're adding /home/capsence/capsence/metisq/httpapi to your system path and then trying to import httpapi.urls, which would look for a file /home/capsence/capsence/metisq/httpapi/httpapi/urls.py (NB httpapi is doubled), not for /home/capsence/capsence/metisq/httpapi/urls.py.

Which version of Django is your code written for, BTW?

well the settings file is in /home/capsence/capsence/metisq/httpapi so I guess the error is somewhere in the settings file...

This application was started quit a number of years ago and has run on a server without any issues for years so we never updated anything... I would have to check...

Could it be to old?

If it's a couple of years old it's actually more likely to run :-) Right now, for Python 2.7 we support Django 1.3 (we're currently hard at work on upgrading that without breaking existing web apps that rely on the old Django version). And 1.3 is a couple of years old.

I reckon you could probably get the app one step closer to working by adding

sys.path.append('/home/capsence/capsence/metisq/)

...to your WSGI file. That would allow you to import stuff both with and without the httpapi

Well that was a good start of the day... It is actually working.

Thanks