473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

md5 hash problems

Hi there,
why is this code generating a problem?
>>input = open('foo.img','rb').read().decode('ISO-8859-1')
import md5
md5.new(input).hexdigest()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xdc' in
position 6:
ordinal not in range(128)
>>>
Thank you.
Sep 30 '08 #1
1 2620
On Tue, Sep 30, 2008 at 2:25 PM, Michele <mi*****@nectarine.itwrote:
Hi there,
why is this code generating a problem?
>>>input = open('foo.img','rb').read().decode('ISO-8859-1')
import md5
md5.new(input).hexdigest()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xdc' in
position 6:
ordinal not in range(128)
You're trying to run md5 over a unicode string, but I'm pretty sure
it's only defined for bytes, and when Python tries to autoconvert the
unicode to bytes (by encoding it in ASCII), this fails because you
particular unicode string contains non-ASCII characters. Basically
make sure to pass md5.new() bytes and not unicode, either by removing
the call to .decode(), or calling .encode() on the unicode object
before passing it to md5.new()

Regards,
Chris
--
Follow the path of the Iguana...
http://rebertia.com
>>>>

Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
Sep 30 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Weiguang Shi | last post by:
Hi there, I'm thinking of using binascii.crc32 as a hash-function when I read in the reference http://www.python.org/doc/current/lib/module-binascii.html: crc32( data) Compute CRC-32, the...
34
by: pembed2003 | last post by:
Hi All, Does C++/STL have hashtable where I can do stuff like: Hashtable h<int>; h.store("one",1); h.store("two",2); and then later retrieve them like:
3
by: Markus Dehmann | last post by:
I have a class "Data" and I store Data pointers in an STL set. But I have millions of inserts and many more lookups, and my profiler found that they cost a lot of runtime. Therefore, I want to...
14
by: al | last post by:
Here's what I am trying to write a simple hash table: struct Employee { char name; int id; char department; float salary; };
2
by: Pieter Claassen | last post by:
But, last few questions if I may: Here is a test program that compiles and works #include <search.h> #include <stdio.h> #include <string.h> typedef struct {
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
11
by: Douglas Dude | last post by:
how much time does it take to lok for a value - key in a hash_map ? Thanks
13
by: ababeel | last post by:
Hi I am using a calloc in a hash table program on an openvms system. The calloc is used to declare the hash table char **pHashes; pHashes = calloc(hash_size,sizeof(char *)); //hash_size = 101 ...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.