Urllib请求不应该返回304

时间:2015-10-05 21:04:21

标签: python http urllib

我最近一直在重新学习Python,我制作了一个小脚本来从网址返回内容。但是,添加“If-Modified-Since”标头时,脚本永远不会给我304错误。即使内容未被修改。

我目前的脚本是:

""" HTTP SERVICES

Program intended to demonstrate the usage of the urllib.request
module (previously urllib2).

"""

import urllib.request as urllib # For getting files off the web
import time  # For delaying purposes


# Getting the actual XML file
request = urllib.Request("some website")

# Get data first time
opener = urllib.build_opener()
feed_data = opener.open(request)
print(feed_data.read())


for i in range(1, 11):
    time.sleep(1)

    # Does not return 304
    request.add_header("If-Modified-Since",
                        feed_data.headers.["Last-Modified"])
    feed_data = opener.open(request)
    print(feed_data.read())

任何人都可以解释为什么它不会返回304错误吗?

0 个答案:

没有答案