Python Eclipse/AntMD5与任何其他md5都不匹配

Python Eclipse/AntMD5与任何其他md5都不匹配,python,eclipse,ant,md5,Python,Eclipse,Ant,Md5,因此,我仍在努力遵循这一点: 我被困在另一个地方,遇到了非常奇怪的MD5问题,我不明白为什么我的Eclipse/Ant计算的MD5与我可以使用md5sum(cygwin)或Python计算的MD5不同 Eclipse/Ant消息: BUILD FAILED D:\eclipseWorkspace\maven.1334761781732\branches\1.2.x\de.tudarmstadt.ukp.dkpro.core.treetagger\src\scripts\build.xml:34

因此,我仍在努力遵循这一点:

我被困在另一个地方,遇到了非常奇怪的MD5问题,我不明白为什么我的Eclipse/Ant计算的MD5与我可以使用md5sum(cygwin)或Python计算的MD5不同

Eclipse/Ant消息:

BUILD FAILED

D:\eclipseWorkspace\maven.1334761781732\branches\1.2.x\de.tudarmstadt.ukp.dkpro.core.treetagger\src\scripts\build.xml:34: The following error occurred while executing this line:
D:\eclipseWorkspace\maven.1334761781732\branches\1.2.x\de.tudarmstadt.ukp.dkpro.core.treetagger\src\scripts\build.xml:311: The following error occurred while executing this line:
D:\eclipseWorkspace\maven.1334761781732\branches\1.2.x\de.tudarmstadt.ukp.dkpro.core.treetagger\src\scripts\build.xml:451: MD5 checksum mismatch for [la-tagger-little-endian.par]. 
Please verify the checksum and if necessary update this script. 
Expected: f959f8633ef842f069f0331ad19dc8b4
Actual  : bde1f6a63b2c5a658ba25a8eb90832a8
好的,这是可能的,因为FTP上的文件可能已更改,以下是ANT的build.xml文件的一部分:

<target name="la">
    <property name="version.la" value="2011050700"/>

    <install-model-file url="ftp://ftp.ims.uni-stuttgart.de/pub/corpora/latin-par-linux-3.2.bin.gz"
        type="tagger" endianness="little-endian" language="la" encoding="ISO-8859-1"
        md5="f959f8633ef842f069f0331ad19dc8b4"/>
</target>
使用python:

import urllib
import hashlib
data = urllib.urlopen("ftp://ftp.ims.uni-stuttgart.de/pub/corpora/latin-par-linux-3.2.bin.gz").read()
md5 = hashlib.md5()
md5.update(data)
print md5.hexdigest()
e77493eed28857bf93aca91c2a6e5a9b


而且还使用来自web的免费软件计算MD5,它们彼此匹配,但不同于ANT计算为“实际”的那个

为了手动计算md5,您应该首先提取文件


使用gunzip或7zip。

我是DKPro核心开发人员。我们执行这些MD5检查的原因是,当远程文件更改时,我们希望在不另行通知的情况下注意到这一点

您不必自己计算MD5总和。脚本告诉您它知道哪些MD5以及它实际得到了什么。若您希望脚本继续运行,只需更新build.xml中记录的MD5,告诉您它是“实际”的MD5。但是,您还应该更新版本

下面这段话来自我们的文章,并解释了其背后的理由:

并非所有的资源都由其维护人员进行了正确的版本控制。我们观察到,资源每天都在变化,没有发布任何公告或增加版本号(如果有)。因此,我们根据build.xml文件中存储的MD5校验和验证所有资源。这样,我们可以注意到远程资源是否已更改。发生这种情况时,我们会在build.xml文件中添加一个注释,指示何时注意到MD5更改会更新相应资源的版本

因为我们没有每天测试build.xml文件,所以当您尝试自己打包资源时,可能会出现MD5校验和错误。如果发生这种情况,请使用文本编辑器打开build.xml文件,找到失败的MD5校验和,更新它并更新相应资源的版本。您也可以在上告诉我们,我们将更新build.xml文件


顺便说一句,本教程同时更改为使用不同的组件,我们可以为其分发模型,因此这应该不再是一个问题。

好的,你说得对,我是个傻瓜。我必须提取所有内容,并对“file=”tree tagger“参数指定的文件计算md5!多谢各位。我对Eclipse/Ant/Maven之类的东西太陌生了。。。
import urllib
import hashlib
data = urllib.urlopen("ftp://ftp.ims.uni-stuttgart.de/pub/corpora/latin-par-linux-3.2.bin.gz").read()
md5 = hashlib.md5()
md5.update(data)
print md5.hexdigest()
e77493eed28857bf93aca91c2a6e5a9b
def md5_for_file(filePath):
    md5 = hashlib.md5()
    file = open(filePath, 'rb')
    while True:
        data = file.read(8192)
        if not data:
            break
        md5.update(data)

    file.close()   
    return md5.hexdigest()

print md5_for_file(r"D:\ftp.ims.uni-stuttgart.de.pub.corpora.20120419\latin-par-linux-3.2.bin.gz")
e77493eed28857bf93aca91c2a6e5a9b