Hello! I ran into an inexplicable situation: there is a cycle that receives the word randomly, and then hashes it in md5 with the help of hashlib and writes it into the .tt file. It gets the words randomly, but for some reason the hash in the output file is the same, as if the same word is hashed. I do not understand why:

import random from hashlib import md5 import requests import time out = input (r'Укажите файл для сохраниния: ') out2 = open (out, 'w') slovar = ('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','1','2','3','4','5','6','7','8','9','0') for i in range (99): randomm = random.choice(slovar) + random.choice(slovar) + random.choice(slovar) + random.choice(slovar) randomm2 = md5(b'randomm').hexdigest() r = requests.get ('http://mysite.com/'+ str(randomm2)) out2.write (randomm2 + '+' + str(r.status_code) + '\n') time.sleep (1) out2.close 
  • just variable randomm could not be left, because you need to add b - babyborn
  • str won't pass for hashing - babyborn
  • [this comment was the first] Let me guess, it turns out 2f8703a73bc2e86bad9a6ddf4631ae43 ? Well, this is a hash from the word randomm , it is in your md5(b'randomm') and spelled out and you take a hash from it. Maybe you wanted md5(randomm) instead? - andreymal
  • another question: do not tell me how to make this line more elegant: randomm = random.choice (slovar) + random.choice (slovar) + random.choice (slovar) + random.choice (slovar) so as not to write the same thing several times ( type * 4) - babyborn
  • one
    For example ''.join(random.choice(slovar) for _ in range(4)) - andreymal

1 answer 1

Problem in line

 randomm2 = md5(b'randomm').hexdigest() 

Above, you have the variable randomm , probably just a typo.

Try to change to:

 randomm2 = md5(randomm.encode()).hexdigest() 
  • yes your option helped, thanks! - babyborn
  • @dimahimma, then accept the answer as correct (check mark to the left of the answer) and check that the answer is useful (up arrow);) - gil9red
  • of course, 34 seconds and put it :) - babyborn