Hi,

On 12.09.19 16:09, Andreas Tille wrote:
> May be some final helping hint could be how to fix leaving the 
> program that leads to:
> 
> 
> Traceback (most recent call last): File "/usr/bin/cycle", line 83,
> in OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file)
> File "/usr/share/cycle/save_load.py", line 27, in Save_Cycle 
> m.update(passwd) TypeError: Unicode-objects must be encoded before 
> hashing
> 
> 
> I tried
> 
> m.update(passwd.encode())
> 
> but this leads later to
> 
> Traceback (most recent call last): File "cycle.py", line 83, in 
> OnCloseWindow Save_Cycle(cycle.name, cycle.passwd, cycle.file) File 
> "/home/andreas/debian-maintain/salsa/med-team/cycle/save_load.py", 
> line 46, in Save_Cycle tmp=rt.encrypt( 'Cycle'+pickle.dumps(objSave) 
> ) TypeError: can only concatenate str (not "bytes") to str
> 
> 
> Since I do not have much experience with hashlib I'd be happy if 
> someone might be able to proof-read `def Save_Cycle` in 
> save_load.py.

This does not have anything to do with hashlib per se.
It's just the usual mess of mixing bytestrings with strings.
You often don't notice in Python2, it just introduces subtle bugs.
Python3 is more strict here and doesn't allow it.

Try this:

tmp = rt.encrypt('Cycle{}'.format(pickle.dumps(objSave)))

As an explanation:

Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> s = 'abc123üöß'
>>> objSave = pickle.dumps(s)
>>> objSave
b'\x80\x03X\x0c\x00\x00\x00abc123\xc3\xbc\xc3\xb6\xc3\x9fq\x00.'
>>> type(objSave)
<class 'bytes'>
>>> print('Cycle'+pickle.dumps(objSave))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "bytes") to str
>>> print('Cycle{}'.format(pickle.dumps(objSave)))
Cycleb'\x80\x03C\x16\x80\x03X\x0c\x00\x00\x00abc123\xc3\xbc\xc3\xb6\xc3\x9fq\x00.q\x00.'

Best wishes
Michael

P.S.: The code is in a bad state regarding whitespace / indentation.
This is critical to get right in Python (e.g. after a for there _has to_
be an indentation added, Python normally uses four spaces, no tabs).


Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to