0
votes

I am trying to generate qr codes using elaphe in a django view. This works fine in the development server but fails under production which is running on apache2 and mod_wsgi (on the same machine as development). Looks to be some kind of ghostscript error. I am guessing something to do with the path environment (gs is installed in /usr/local/bin).

Error

Exception Type: IOError Exception Value:
[Errno 32] Broken pipe

/usr/local/web/django/www/production/recipemonkey/recipemonkeyapp/views/groceryitem.py in barcodeimg

  • img.save(response, 'PNG') ...

/usr/local/web/django/www/production/env/recipemonkey/lib/python2.7/site-packages/PIL/Image.py in save

  • self.load() ...

/usr/local/web/django/www/production/env/recipemonkey/lib/python2.7/site-packages/PIL/EpsImagePlugin.py in load

  • self.im = Ghostscript(self.tile, self.size, self.fp) ...

/usr/local/web/django/www/production/env/recipemonkey/lib/python2.7/site-packages/PIL/EpsImagePlugin.py in Ghostscript

  • gs.write(s) ...

Code

def barcodeimg(request, id):

try:
    i = GroceryItem.objects.get(pk=id)
except GroceryItem.DoesNotExist:
    raise Http404

response=HttpResponse(content_type='image/png')

url="http://%s/recipemonkeyapp/scan/groceryitem/%s" % ('192.168.0.8:8082',i.id)

img=barcode('qrcode',url,options=dict(version=9, eclevel='M'), margin=0, data_mode='8bits')   # Generates PIL.EpsImageFile instance

img=img.resize((90,90)) #both these lines generate IOErrors

img.save(response, 'PNG') #both these lines generate IOErrors

return response
2

2 Answers

0
votes

Ensure you are using absolute path for file being saved. Current working directory under Apache can be anything. Also ensure that directory file being saved to is writable to user that code runs as under Apache.

0
votes

Fixed via a symbolic link. Clearly was a PATH issue or hardcoded reference to the gs binary.

sudo ln -s /usr/local/bin/gs /usr/bin/gs