如何使用 python3 urllib 获取最后修改时间?
我正在从 python2 移植 我的程序到 python3,我遇到了以下错误: AttributeError: 'HTTPMessage' object has no attribute 'getdate'
这是代码:
conn = urllib.request.urlopen(fileslist, timeout=30)
last_modified = conn.info().getdate('last-modified')
本节在 python 2.7 下工作,到目前为止我还没有能够找到在python 3.1中获取此信息的正确方法。
完整的上下文是一个更新方法。它将新文件从服务器拉到本地数据库,但前提是服务器上的文件比本地文件新。如果有一种比仅比较本地和远程文件时间戳更智能的方法来实现此功能,那么我也对此持开放态度。
I'm porting over a program of mine from python2 to python3, and I'm hitting the following error: AttributeError: 'HTTPMessage' object has no attribute 'getdate'
Here's the code:
conn = urllib.request.urlopen(fileslist, timeout=30)
last_modified = conn.info().getdate('last-modified')
This section worked under python 2.7, and so far I haven't been able to find out the correct method to get this information in python 3.1.
The full context is an update method. It pulls new files from a server down to its local database, but only if the file on the server is newer than the local file. If there's a smarter way to achieve this functionality than just comparing local and remote file timestamps, then I'm open to that as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
conn.headers['last-modified']
在 Python 2 和 Python 3 下都可以工作。比较文件戳对我来说似乎是合理的。conn.headers['last-modified']
works under both Python 2 and Python 3. Comparing filestamps seems reasonable to me.