[英]Php md5 different from python
I'm trying to get the md5 in both php and python, but I'm not sure why the results are different, I have read in other questions about hashing strings but not files and I've also tried the echo -n but I get a syntax error. 我正在尝试同时在php和python中获取md5,但我不确定为什么结果会有所不同,我已经阅读了其他有关散列字符串而不是文件的问题,并且还尝试了echo -n但我得到语法错误。
Php: Php:
<?php
echo 'MD5 file hash : ' . md5_file('https://cdn4.buysellads.net/uu/1/8026/1533152372-laptop_purple_graph.png');
?>
MD5 file hash : 5e81ca561d2c1e96b5e7a2e57244c8e5
MD5文件哈希:5e81ca561d2c1e96b5e7a2e57244c8e5
python: 蟒蛇:
import hashlib
m=hashlib.md5('https://cdn4.buysellads.net/uu/1/8026/1533152372-laptop_purple_graph.png')
print('The MD5 checksum is',m.hexdigest())
MD5 file hash : 52e8e2e35519e8f6da474c5e1dc6d258
MD5文件哈希:52e8e2e35519e8f6da474c5e1dc6d258
In Python snippet you are hashing the https://cdn4.buysellads.net/uu/1/8026/1533152372-laptop_purple_graph.png
string, which I guess is different from the contents. 在Python代码段中,您对
https://cdn4.buysellads.net/uu/1/8026/1533152372-laptop_purple_graph.png
字符串进行了哈希处理,我猜这与内容有所不同。
You need to fetch url contents first and pass it to hashlib.md5
: 您需要首先获取url内容并将其传递给
hashlib.md5
:
import urllib.request
import hashlib
contents = urllib.request.urlopen("https://cdn4.buysellads.net/uu/1/8026/1533152372-laptop_purple_graph.png").read()
m = hashlib.md5(content)
print('The MD5 checksum is',m.hexdigest())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.