How can I get the last-modified time with python3 urllib?

浪尽此生 提交于 2019-12-10 12:36:09

问题


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.


回答1:


conn.headers['last-modified'] works under both Python 2 and Python 3. Comparing filestamps seems reasonable to me.



来源:https://stackoverflow.com/questions/5022083/how-can-i-get-the-last-modified-time-with-python3-urllib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!