Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8417023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:55:45+00:00 2026-06-10T01:55:45+00:00

I’m using the hashlib func in a script I’m writing, and I can’t get

  • 0

I’m using the hashlib func in a script I’m writing, and I can’t get it to take the files I’m pointing it towards – its only returning the hash of a 0kb file d41d8cd98f00b204e9800998ecf8427e.

I’m calling it like so: fHash=md5Checksum(f) where f is a full path string of a file.

The md5Checksum func is a lift from here: http://www.joelverhagen.com/blog/2011/02/md5-hash-of-file-in-python/ and I’ve tested the 2nd example directly with an explicitly typed path to a file and it returns the correct hash.

I am also using the os.path.getsize method in the same way (fSize=os.path.getsize(f)) and that is picking the file up correctly.

When I dump the contents of the f string in my code, and compare it to the explicitly typed path, I notice it lacks ' markers around the string:

/home/.../(500) Days of Summer[2009]/11 - Regina Spektor - Hero.mp3 from a ‘print f’

and from the explicitly typed path:

print 'The MD5 checksum of text.txt is', md5Checksum('/home/.../deduper/test.txt') (which works)

If I manually add ' markers to the path the code falls over:

IOError: [Errno 2] No such file or directory: "'/home/.../(500) Days of Summer[2009]/11 - Regina Spektor - Hero.mp3'"

This makes me suspect I’m not passing the path correctly. I’m on a ubuntu box if that matters.

EDIT

I’m a buffoon. I’ve been stuck on this for a few days, and its only through posting it on here and checking the indentations I’ve noticed I’ve messed one of them up on the md5Checker method along the way… I’ve fixed it, and this totally works. Thank you all for making me check…. (for the record, I had the m.update(data) line inline with the break. Thats not going to work now is it…. :s

def md5Checksum(filePath):
 fh = open(filePath, 'rb')
 m = hashlib.md5()
 # print "File being hashed: " + filePath
 while True:
  data = fh.read(8192)
  if not data:
   break
  m.update(data)
 return m.hexdigest()   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:55:47+00:00Added an answer on June 10, 2026 at 1:55 am

    I had somehow got the indentation misalign, not enough to cause it to fall over and give me an error, but enough for it to not work. Answer is posted in the original question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.