This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Fix the example in hashlib documentarion
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: cheryl.sabella, docs@python, marcelogrsp@gmail.com
Priority: normal Keywords:

Created on 2020-06-12 11:36 by marcelogrsp@gmail.com, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg371354 - (view) Author: Marcelo (marcelogrsp@gmail.com) Date: 2020-06-12 11:36
The documentation found in https://docs.python.org/2/library/hashlib.html

give us the following example:

```
More condensed:

>>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest()
'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
```

Although, we get the error if not encode the string:
```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Unicode-objects must be encoded before hashing
```

So the example should be (string to bytes):
`hashlib.sha224(b"Nobody inspects the spammish repetition").hexdigest()`
msg371355 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2020-06-12 11:48
Hi Marcelo,

Thanks for the report.  The version of the documentation that you linked to is for Python 2.  At the top of that page, there is a redirect to the Python 3 documentation at https://docs.python.org/3/library/hashlib.html.  You'll see that the Python 3 documentation does use bytes for that example.
msg371416 - (view) Author: Marcelo (marcelogrsp@gmail.com) Date: 2020-06-12 20:45
ooops, thank you!
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85132
2020-06-12 20:45:34marcelogrsp@gmail.comsetmessages: + msg371416
2020-06-12 11:48:23cheryl.sabellasetstatus: open -> closed

nosy: + cheryl.sabella
messages: + msg371355

resolution: not a bug
stage: resolved
2020-06-12 11:36:43marcelogrsp@gmail.comcreate