Good Afternoon, for several days i try, to getting the Python QR-Code Module from lincolnloop running under Python3. It runs perfect on Python 2.x. - https://github.com/lincolnloop/python-qrcode
In general i'am very new to Python Programming but i think i have done my homework so far.
First Error:
File "/usr/lib/python3.2/qrcode/util.py", line 274, in __init__
if not isinstance(data, basestring):
NameError: global name 'basestring' is not defined
So basestring didnt exist in Python3 anymore i fix this with this Code Statement found here. - https://github.com/oxplot/fysom/issues/1
try:
unicode = unicode
except NameError:
# 'unicode' is undefined, must be Python 3
str = str
unicode = str
bytes = bytes
basestring = (str,bytes)
else:
# 'unicode' exists, must be Python 2
str = str
unicode = unicode
bytes = str
basestring = basestring
So the next Error comes up.
File "/usr/lib/python3.2/qrcode/util.py", line 285, in __init__
elif re.match('^[%s]*$' % re.escape(ALPHA_NUM), data):
File "/usr/lib/python3.2/re.py", line 153, in match
return _compile(pattern, flags).match(string)
TypeError: can't use a string pattern on a bytes-like object
So i try the solution found here - Python TypeError on regex and change the following code from:
elif re.match('^[%s]*$' % re.escape(ALPHA_NUM), data):
to:
elif re.match(b'^[%s]*$' % re.escape(ALPHA_NUM), data):
to Handle the RegEx in Binary Mode. But this throws the next execption in the same line of Code.
elif re.match(b'^[%s]*$' % re.escape(ALPHA_NUM), data):
TypeError: unsupported operand type(s) for %: 'bytes' and 'str'
I also try to change
ALPHA_NUM = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
to
ALPHA_NUM = b'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'
But this makes no changes to the Execption.
So this indicates for me the same error as the one before, and anywhere in the code must be this type error wether its bytes or string type. But i cant find it.
I know the whole script is very complex for diving into python, but for my project, i need a working QR Code generator.
Can somebody give me a clue? Thanks in advance!