0

I want to execute hash algorithm. So, I made this code. I also imported hashlib. But, in the last line, an error happened:

KeyError: PyQt4.QtCore.QString(u'sha1')

I don't know what the problem is. Here is the code:

def setupUi(self, MainWindow)
    self.radioLabel = 'sha256'  #default 256
    self.combo.currentIndexChanged.connect(self.OnRadiogroup)

def OnRadiogroup(self,radioLabel)
    self.radioLabel = radioLabel
    self.radioLabel = self.combo.currentText() #get selected hash string

def create_matchkey(self, row, path, key, radioLabel):

    hash_function = {"sha1":hashlib.sha1,
                     "sha224":hashlib.sha224,
                     "sha256":hashlib.sha256,
                     "sha512":hashlib.sha512,
                     "md5":hashlib.md5}
    hash_object = hash_function[radioLabel](self.input_str)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
Layla
  • 51
  • 9
  • you must provide a [mcve], that is, I can copy your code and run it without problems, but your example is not. – eyllanesc Nov 23 '17 at 01:37

1 Answers1

0

You need to convert the QString from the radioLabel into a python string:

hash_object = hash_function[str(radioLabel)](self.input_str)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336