0

This is my code

import httplib2

httplib2.debuglevel = 1

h = httplib2.Http(".cache")

response, content = h.request('http://diveintopython3.org/examples/feed.xml')

print(response.fromcache)

swapnil
  • 29
  • 2

2 Answers2

0

The link(http://diveintopython3.org/examples/feed.xml) I was using in my code is inactive now that why I was facing such issue.

swapnil
  • 29
  • 2
0

Using a resource that, at time of writing, exists and declares itself cachable:

#!/usr/bin/python3

import httplib2

h = httplib2.Http('cache')

response, content = h.request('https://example.com/')
print(response.status)
print(response.fromcache)

response, content = h.request('https://example.com/')
print(response.status)
print(response.fromcache)

Gives:

200
False
200
True

on the first run, indicating that both requests were successful, and that the second was served from the cache. Running it again gives:

200
True
200
True

as the cache is persisted on disk from the previous run.

Joe
  • 29,416
  • 12
  • 68
  • 88