Forums

Weaseyprint, Cairo, Dajngo on Pythonanywhere 25MAY21

Hello,

Sorry I know there seems to be a lot about this topic. But I do not see a real resolution?

I am trying to place a Django ecommerce pizza shop for learning Django on the website. Locally this works great no issues. I matched my environment locally to that on the ENV for the server. I got this issue resolved locally when I updated Cairo on my computer. So the emulated server works great.

Python 3.8.0

Here is the error and follow on info.

Error from error log on ther server. 2021-05-28 16:13:41,156: /home/williamc1jones/.virtualenvs/myvirtualenv/lib/python3.8/site-packages/weasyprint/document.py:35: UserWarning: There are known rendering problems and missing features with cairo < 1.15.4. WeasyPrint may work with older versions, but please read the note about the needed cairo version on the "Install" page of the documentation before reporting bugs. http://weasyprint.readthedocs.io/en/latest/install.html

views.py file in order app

import weasyprint   
from django.urls import reverse
from django.shortcuts import render, redirect
from django.contrib.admin.views.decorators import staff_member_required
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
from cart.cart import Cart
from .models import OrderItem, Order
from .forms import OrderCreateForm
from .tasks import order_created


def order_create(request):
    cart = Cart(request)
    if request.method == 'POST':
        form = OrderCreateForm(request.POST)
        if form.is_valid():
            order = form.save()
            for item in cart:
                OrderItem.objects.create(order=order,
                                         product=item['product'],
                                         price=item['price'],
                                         quantity=item['quantity'])
            # clear the cart
            cart.clear()
            # launch asynchronous task
            order_created.delay(order.id)
            # set the order in the session
            request.session['order_id'] = order.id
            # redirect for payment
            return redirect(reverse('payment:process'))
    else:
        form = OrderCreateForm()
    return render(request,
                  'orders/order/create.html',
                  {'cart': cart, 'form': form})


@staff_member_required
def admin_order_detail(request, order_id):
    order = get_object_or_404(Order, id=order_id)
    return render(request,
                  'admin/orders/order/detail.html',
                  {'order': order})


@staff_member_required
def admin_order_pdf(request, order_id):
    order = get_object_or_404(Order, id=order_id)
    html = render_to_string('orders/order/pdf.html',
                            {'order': order})
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = f'filename=order_{order.id}.pdf'
    weasyprint.HTML(string=html).write_pdf(response,
        stylesheets=[weasyprint.CSS(
            settings.STATIC_ROOT + 'css/pdf.css')])
    return response

A pip freeze shot of the env

-f /usr/share/pip-wheels
amqp==2.6.1
appdirs==1.4.4
billiard==3.6.4.0
braintree==3.59.0
cairocffi==1.2.0
CairoSVG==2.5.2
celery==4.4.2
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==8.0.1
cssselect2==0.4.1
defusedxml==0.7.1
distlib==0.3.1
Django==2.1.15
django-pyodbc-azure-2019==2.1.0.0
filelock==3.0.12
Flask==2.0.1
Flask-WeasyPrint==0.6
html5lib==1.1
idna==2.10
itsdangerous==2.0.1
Jinja2==3.0.1
kombu==4.6.11
MarkupSafe==2.0.1
pbr==5.5.1
pdfrw==0.4
Pillow==8.2.0
pycparser==2.20
pyodbc==4.0.30
Pyphen==0.10.0
pyth==0.6.0
pytz==2021.1
requests==2.25.1
six==1.15.0
stevedore==3.3.0
tinycss2==1.1.0
urllib3==1.26.4
vine==1.3.0
virtualenv==20.4.4
virtualenv-clone==0.5.4
virtualenvwrapper==4.8.4
wcwidth==0.2.5
WeasyPrint==52
webencodings==0.5.1
Werkzeug==2.0.1
whitenoise==5.2.0

My website is tested at http://williamc1jones.pythonanywhere.com/

Sorry, I may be missing something but -- what is the actual issue you're referring to? UserWarning is (usually) a warning, not an error. Is something not working as expected?

Yes this is one of the weird times that the warning is an error. I know this because I had the exact same issue on my local computer. When I updated Cairo on my computer, the warning went away, and then it worked correctly. As of right now, though you wont see it in the error log. It gets stuck in a loop, and won't bypass to the credit card input on the next screen.

Ok did a little more research. weasyprint requires cairo ≥ 1.15.4. But it looks like you there is cairo 1.14.6. Is there a way to update this?

We are working on a new system image that will have updates of pretty much everything. We hope to have that available in the next few weeks.

Understood and thank you for your help

It looks like the latest versions of Weasyprint (> 52.5) no long require Cairo, but it needs Pango ≥ 1.4.4. It looks like the system image has Pango 1.38.1.

Any chance you can update Pango when you create the new system image?

Sure. We can do that.

Having the same issue Weasyprint requires Pango >= 1.44.0 and the version on PythonAnywhere is 1.38.1 (pango-view --version).

FYI Weasyprint docu: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html

You're using an old system image. Update your system image to get a newer version of Pango.

We switched to Glastonbury and it has the latest versions of Pango / Weasyprint