django + mod_wsgi + ghostscript - IOError Broken Pipe

时间:2011-11-07 11:25:06

标签: django mod-wsgi ghostscript

我正在尝试使用django视图中的elaphe生成qr代码。这在开发服务器中工作正常,但在apache2和mod_wsgi(与开发在同一台机器上)上运行的生产中失败。看起来是某种ghostscript错误。我猜测与路径环境有关(gs安装在/ usr / local / bin中)。

错误

异常类型:IOError 例外价值:
[Errno 32]破管

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

  • img.save(回复,'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)...
Ghostscript中的 /usr/local/web/django/www/production/env/recipemonkey/lib/python2.7/site-packages/PIL/EpsImagePlugin.py

  • gs.write(s)...

代码

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 个答案:

答案 0 :(得分:0)

确保使用绝对路径保存文件。 Apache下的当前工作目录可以是任何东西。还要确保保存到的目录文件可写入用户,该代码在Apache下运行。

答案 1 :(得分:0)

通过符号链接修复。显然是一个PATH问题或对gs二进制文件的硬编码引用。

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