book export isn't working
  • How do I debug the book export function? If starting a book export nothing happens except a message to wait for the export.  
    Post edited by tristank at 2017-01-26 17:56:51
  • 11 Comments sorted by
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Which export option are you using please?
  • Sorry for the delay. I'm using the EPUB export option. After hitting the EXPORT YOUR BOOK button it just shows a message saying 'Exporting, please wait' forever.
    Post edited by tristank at 2017-03-21 13:36:38
  • I tried exporting the ebook with the command line tools, but it fails with an error. After googling I found an issue reported by you at https://dev.sourcefabric.org/browse/BK-1929

    $ source /usr/local/src/mybooktype/bin/activate
    $ cd /var/www/booktype/instance1/
    $ sudo su www-data
    $ . ./booktype.env

    $ django-admin.py bookexport --output book.zip bookname
    Traceback (most recent call last):
      File "/usr/local/bin/django-admin.py", line 5, in <module>
        management.execute_from_command_line()
      File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
        utility.execute()
      File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 195, in fetch_command
        klass = load_command_class(app_name, subcommand)
      File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 39, in load_command_class
        module = import_module('%s.management.commands.%s' % (app_name, name))
      File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/usr/local/src/mybooktype/local/src/booktype/lib/booki/editor/management/commands/bookexport.py", line 19, in <module>
        from booki.editor import common, models
      File "/usr/local/src/mybooktype/local/src/booktype/lib/booki/editor/common.py", line 41, in <module>
        from booki.bookizip import get_metadata, add_metadata, DC, FM
    ImportError: No module named bookizip

    Is there anything I can do to workaround the error? This essentially breaks the main feature of booktype.

    Post edited by tristank at 2017-03-21 14:11:26
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    Hi, thanks for the report of the command line export failure, I will alert the developer team.

    As for the message saying 'Exporting, please wait' forever, that sounds like your background tasks aren't running. Please see the section 'Running celery with supervisor' in http://sourcefabric.booktype.pro/booktype-21-for-authors-and-publishers/manual-installation-on-gnulinux/

  • I checked for the background tasks and restarted the server. It's still frozen at the Export.
    $ sudo supervisorctl
    celeryd                          RUNNING    pid 9651, uptime 0:04:25
    supervisor>quit
    Here's the output of booktype-celery.error.log. There seems to be something wrong with the NAME Value in the database. Any suggestions?

    $ cat /var/www/booktype/instance1/logs/booktype-celery.error.log

      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 253, in trace_task
        I, R, state, retval = on_error(task_request, exc, uuid)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 201, in on_error
        R = I.handle_error_state(task, eager=eager)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 85, in handle_error_state
        }[self.state](task, store_errors=store_errors)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 118, in handle_failure
        req.id, exc, einfo.traceback, request=req,
      File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 133, in mark_as_failure
        traceback=traceback, request=request)
      File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 271, in store_result
        request=request, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/djcelery/backends/database.py", line 29, in _store_result
        traceback=traceback, children=self.current_task_children(request),
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 42, in _inner
        return fun(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 181, in store_result
        'meta': {'children': children}})
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 87, in update_or_create
        return get_queryset(self).update_or_create(**kwargs)
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 70, in update_or_create
        obj, created = self.get_or_create(**kwargs)
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 465, in get_or_create
        return self.get(**lookup), False
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 381, in get
        num = len(clone)
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 240, in __len__
        self._fetch_all()
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1074, in _fetch_all
        self._result_cache = list(self.iterator())
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 52, in __iter__
        results = compiler.execute_sql()
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 846, in execute_sql
        cursor = self.connection.cursor()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 231, in cursor
        cursor = self.make_debug_cursor(self._cursor())
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 204, in _cursor
        self.ensure_connection()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 199, in ensure_connection
        self.connect()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 170, in connect
        conn_params = self.get_connection_params()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/base.py", line 157, in get_connection_params
        "settings.DATABASES is improperly configured. "
    ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.
    [2017-03-22 16:56:33,669: INFO/MainProcess] Received task: booktype.apps.edit.tasks.publish_book[b2b4490e-af1a-48de-83ab-1150bd39c2cf]
    [2017-03-22 16:56:33,670: DEBUG/Worker-7] {'username': u'klocke', 'bookid': u'1', 'clientid': u'268', 'sputnikid': u'v2gr79cachi68ovran0m2u4qz9gos5jx:268', 'version': u'1.0', 'formats': [u'epub']}
    [2017-03-22 16:56:33,675: CRITICAL/MainProcess] Task booktype.apps.edit.tasks.publish_book[b2b4490e-af1a-48de-83ab-1150bd39c2cf] INTERNAL ERROR: ImproperlyConfigured('settings.DATABASES is improperly configured. Please supply the NAME value.',)
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 253, in trace_task
        I, R, state, retval = on_error(task_request, exc, uuid)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 201, in on_error
        R = I.handle_error_state(task, eager=eager)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 85, in handle_error_state
        }[self.state](task, store_errors=store_errors)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 118, in handle_failure
        req.id, exc, einfo.traceback, request=req,
      File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 133, in mark_as_failure
        traceback=traceback, request=request)
      File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 271, in store_result
        request=request, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/djcelery/backends/database.py", line 29, in _store_result
        traceback=traceback, children=self.current_task_children(request),
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 42, in _inner
        return fun(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 181, in store_result
        'meta': {'children': children}})
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 87, in update_or_create
        return get_queryset(self).update_or_create(**kwargs)
      File "/usr/local/lib/python2.7/dist-packages/djcelery/managers.py", line 70, in update_or_create
        obj, created = self.get_or_create(**kwargs)
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 465, in get_or_create
        return self.get(**lookup), False
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 381, in get
        num = len(clone)
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 240, in __len__
        self._fetch_all()
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 1074, in _fetch_all
        self._result_cache = list(self.iterator())
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 52, in __iter__
        results = compiler.execute_sql()
      File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 846, in execute_sql
        cursor = self.connection.cursor()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 231, in cursor
        cursor = self.make_debug_cursor(self._cursor())
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 204, in _cursor
        self.ensure_connection()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 199, in ensure_connection
        self.connect()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/base/base.py", line 170, in connect
        conn_params = self.get_connection_params()
      File "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/base.py", line 157, in get_connection_params
        "settings.DATABASES is improperly configured. "
    ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value.

    Post edited by tristank at 2017-03-22 12:04:40
  • Vote Up0Vote Down Daniel JamesDaniel James
    Posts: 844Member, Sourcefabric Team
    If you take a look at your dev.py or prod.py settings file, the NAME value is part of the database settings stanza. So for example if you are using a postgresql database called booktype-db it should be something like:
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'booktype-db',
  • Looks alright to me. I dont get it.
    $ cat /var/www/booktype/instance1/instance1_site/settings/prod.py | grep NAME
            'NAME': 'booktype-db',
    $ cat /var/www/booktype/instance1/instance1_site/settings/prod.py | grep ENGINE
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
  • I'm afraid I'm also running into the same issue. Our test server works as expected (dev settings), but when we try to export from our production server (with prod settings), the logs show exactly the same configuration errors. As if the production instance couldn't use the Django settings.

    Both instances use different databases and Celery instances, and separate Redis ports, as explained in the documentation. Supervisor shows the two instances running correctly. Very annoying.
  • Got it! In the _site/celery.py file, the DJANGO_SETTINGS_MODULE setting is set to dev, whatever we have in the Django base settings file. Changing the value to point to the prod environment and restarting Apache and Supervisor fixed the issue.
    So it would be great if the celery.py file could reuse the Django settings. I'm going to check the bug tracker and add a new report if necessary.

    Meanwhile, would someone with write access be willing to add a line in the install documentation? Thanks!
    Post edited by Nicolas Dufour at 2018-12-05 07:38:28
  • Hi Nicolas Dufour, 

    Best.