How to get MD5 sum of a string using python?

后端 未结 6 1213
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 09:07

In the Flickr API docs, you need to find the MD5 sum of a string to generate the [api_sig] value.

How does one go about generating an MD5 sum from a str

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 09:52

    You can do the following:

    Python 2.x

    import hashlib
    print hashlib.md5("whatever your string is").hexdigest()
    

    Python 3.x

    import hashlib
    print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest())
    

    However in this case you're probably better off using this helpful Python module for interacting with the Flickr API:

    • http://stuvel.eu/flickrapi

    ... which will deal with the authentication for you.

    Official documentation of hashlib

提交回复
热议问题