Booktype over HTTPS
  • Hello all

    I made a new attempt at installing and running Booktype 2.4, using the manual installation procedure (on a DigitalOcean droplet).  Seems to work fine, but it will not run properly over HTTPS.

    I can get the Letsencrypt certificate up and running no problem, but get mixed content warnings in both Firefox and Chrome, and many interface menu-icons will not show up when using HTTPS, thus it's almost impossible for ordinary users to figure out how to use Booktype. (They have to guess the functionality of a menu item button, and hope it does not destroy something)

    I see other people have similar problems using https with Superdesk. https://forum.sourcefabric.org/discussion/18977/superdesk-over-https

    Why would a clean installation get mixed content warnings? And what could be the reason interface menu-icons not show up in https?
    Post edited by Graabein at 2019-03-17 07:59:54
  • 8 Comments sorted by
  • When viewing the website in https, and then hitting F12 in the browser to view the console, it is full of references to http:// urls collected from "CACHE", "static" and "data" directories.

    It seems like the installation process has created some static url references to http://, that ofcourse will not work when site is viewed in https://

    Do I have to rebuild the app after configuring the Letsencrypt certificate, or are there some settings I can change in base.py or prod.py to get this to work properly?

    What to do?

    Attached is the log from the browser console.  This is what shows when visiting the site as guest, when logged in these results increase by a great number.
    Post edited by Graabein at 2019-03-17 15:11:12
  • OK, I editet prod.py

    Changed BOOKTYPE_URL to https://

    Then I ran
    ./manage_prod.py collectstatic

    ./manage_prod.py compress

    Then restarted server, cleared browser cache. Now mixed content errors are gone and it seems to work.

    However, now - after installing SSL certificate - exporting books don't work any longer, it just hangs there with a message saying "Exporting, please wait".  It did work as expected before I installed SSL.

    Here is what I found in booktype-celery.error.log, the only thing I found related to any export/publishing error

    [2019-03-18 23:35:23,818: ERROR/ForkPoolWorker-12] Task booktype.apps.edit.tasks.publish_book[b534fb3a-f862-4282-939f-da2fa6084414] raised unexpected: UnboundLocalError("local variable 'req' referen$
    Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 375, in trace_task
        R = retval = fun(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 632, in __protected_call__
        return self.run(*args, **kwargs)
      File "/usr/local/src/booktype/lib/booktype/apps/edit/tasks.py", line 116, in publish_book
        result = download.fetch_url(convert_url, data, method='POST')
      File "/usr/local/src/booktype/lib/booktype/utils/download.py", line 36, in fetch_url
        if req.status_code != 200:
    UnboundLocalError: local variable 'req' referenced before assignment

    Post edited by Graabein at 2019-03-18 19:28:05
  • Hi Graabein,

    What value do you have for `CONVERT_URL` in the prod.py?
  • Hi Oleg

    CONVERT_URL = BOOKTYPE_URL

    and BOOKTYPE_URL says

    BOOKTYPE_URL = os.environ.get('BOOKTYPE_URL', 'https://domainnameeditedforprivacy.tld')


    Post edited by Graabein at 2019-03-19 09:54:32
  • Hi @oleg.pshenichniy, are you there?
    Post edited by Graabein at 2019-03-26 17:13:34
  • Is there anyone able to help me find a solution to the export problem?
  • This is a bit frustrating, have waited two months for some help.......maybe it would be better to rename this forum?

  • UnboundLocalError: local variable 'req' referenced before assignment



    Python has lexical scoping by default, which means that although an enclosed scope can access values in its enclosing scope, it cannot modify them (unless they're declared global with the global keyword). A closure binds values in the enclosing environment to names in the local environment. The local environment can then use the bound value, and even reassign that name to something else, but it can't modify the binding in the enclosing environment. UnboundLocalError happend because when python sees an assignment inside a function then it considers that variable as local variable and will not fetch its value from enclosing or global scope when we execute the function. To modify a global variable inside a function, you must use the global keyword.