| Issue 2: | cannot concatenate 'str' and 'int' objects |
1 of 10
Next ›
|
| 3 people starred this issue and may be notified of changes. | Back to list |
Hi, First, thanks for this cool tool. I'm using it in my project: http://bitbucket.org/cedricbonhomme as you can see here: http://www.google.com/buzz/kimble.mandel/Mjua2Gu3qT5/Pour-lire-un-article-plus-tard-avec-son-t%C3%A9l%C3%A9pho So, my goal is to make QR Code from URL of articles in my Python aggregator. But when a URL is too long I have this error: """ [23/Jul/2010:12:06:01] HTTP Traceback (most recent call last): File "/usr/local/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 606, in respond cherrypy.response.body = self.handler() File "/usr/local/lib/python2.7/site-packages/cherrypy/_cpdispatch.py", line 25, in __call__ return self.callable(*self.args, **self.kwargs) File "pyAggr3g470r.py", line 373, in description qr.make() File "/home/cedric/prog/python/projects/pyaggr3g470r/PyQRNative.py", line 58, in make self.makeImpl(False, self.getBestMaskPattern() ) File "/home/cedric/prog/python/projects/pyaggr3g470r/PyQRNative.py", line 109, in getBestMaskPattern self.makeImpl(True, i); File "/home/cedric/prog/python/projects/pyaggr3g470r/PyQRNative.py", line 82, in makeImpl self.dataCache = QRCode.createData(self.typeNumber, self.errorCorrectLevel, self.dataList) File "/home/cedric/prog/python/projects/pyaggr3g470r/PyQRNative.py", line 284, in createData + ")") TypeError: cannot concatenate 'str' and 'int' objects """ And this is how I call your code: """ if not os.path.isfile("./var/qrcode/"+article_id+".png"): # QR code generation try: qr = PyQRNative.QRCode(5, PyQRNative.QRErrorCorrectLevel.L) qr.addData(article[3]) qr.make() im = qr.makeImage() im.save("./var/qrcode/"+article_id+".png", format='png') except Exception, e: # Code length overflow print e """ See here: http://bitbucket.org/cedricbonhomme/pyaggr3g470r/src/tip/pyAggr3g470r.py#cl-367 Since I'm using 5 as first argument of QRCode(), it is impossible to generate QR code from some (too long I think) URL. So I think there is a little bug here in your code: https://code.google.com/p/pyqrnative/source/browse/trunk/pyqrnative/src/PyQRNative.py#279 when you raise the exception. I've fixed the problem locally just by doing that: """ if (buffer.getLengthInBits() > totalDataCount * 8): raise Exception("code length overflow. (" + str(buffer.getLengthInBits()) + ">" + str(totalDataCount * 8) + ")") """ I hope my notice is useful for you, thanks, Cédric
May 12, 2011
I fixed this. Get the code here: https://github.com/unapiedra/pyqrnative I'll attach a patch. |
You're better off _not_ commenting that out. The reason why it fails, is because : Indirectly : you have reached the maximum amount of data that can be stored in the QRcode. Directly : This person roughly converted a javascript library of the same nature, where simply joining any data type with strings is acceptable and causes no exceptions. however in python, you will need to use a more appropriate method of joining data with strings. raise Exception("code length overflow. ( %s > %s )" % (buffer.getLengthInBits(),totalDataCount * 8) ) you might want to do this for every single bit of concatenation in the code