Python Barcode Generation -
i'm using elaphe package python generate ean-13 barcode images. package installed source using tar file found @ https://pypi.python.org/pypi/elaphe.
when run code:
barcode_image_path = "/tmp/" def create_barcode_image(product_barcode): path = barcode_image_path + product_barcode + '.png' img = barcode('ean13', product_barcode, options=dict(includetext=true, height=0.4), margin=1) img.save(path, 'png') return path
from python interpreter seems work perfectly. correct barcode generated path specify. when run apache using web.py web framework receive error:
traceback (most recent call last): ... img_path = create_barcode_image(barcode) file "/var/www/py/documents/barcode_images.py", line 27, in create_barcode_image img.save(path, 'png') file "/usr/local/lib/python2.7/dist-packages/pil/image.py", line 1406, in save self.load() file "/usr/local/lib/python2.7/dist-packages/pil/epsimageplugin.py", line 283, in load self.im = ghostscript(self.tile, self.size, self.fp) file "/usr/local/lib/python2.7/dist-packages/pil/epsimageplugin.py", line 75, in ghostscript raise ioerror("gs failed (status %d)" % status) ioerror: gs failed (status 256)
does know might causing error or how go debugging it?
add in debug statements can walk through:
import sys barcode_image_path = "/tmp/" def create_barcode_image(product_barcode): print >> sys.stderr, "product_barcode: %s" % product_barcode path = barcode_image_path + product_barcode + '.png' print >> sys.stderr, "path: %s" % path img = barcode('ean13', product_barcode, options=dict(includetext=true, height=0.4), margin=1) print >> sys.stderr, "img data: %s" % img.tostring() img.save(path, 'png') print >> sys.stderr, "saved %s" % path return path
then in shell:
$ tail -f /var/log/httpd/error.log # or wherever put
you're looking for: first: output of "product_barcode: ...
". that's not blank. if is, problem lies elsewhere, maybe in server config. output of "img data: ...
". it's png , not blank. if it's blank, problem lies ghostscript installation.
this rudimentary way of debugging, , feel small projects easy throw in debug statements rather messing around debugger, can difficult set properly.
Comments
Post a Comment