From 70ff55c8dad85496d5fe6abf29c4d43d334063b3 Mon Sep 17 00:00:00 2001 From: David Watson Date: Tue, 22 Dec 2015 15:16:09 -0500 Subject: [PATCH] Extract resultset size from Content-Range --- docs/examples/python-requests-jwt.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/examples/python-requests-jwt.md b/docs/examples/python-requests-jwt.md index a82ca0157..7a5454d1f 100644 --- a/docs/examples/python-requests-jwt.md +++ b/docs/examples/python-requests-jwt.md @@ -28,6 +28,12 @@ Then, from a python interpreter or script: if r.status_code != 200: raise Exception() + # Make a request to get the range header + r = requests.get('http://localhost:3000/posts', auth=auth) + + # Extract the size of the resultset from the Content-Range + upper_bound = int(r.headers['Content-Range'].split('/')[1]) + # Handle pagination using the Range header for i in range(0, upper_bound, 20): this_range = '{0}-{1}'.format(i, i+20 if i+20 < upper_bound else upper_bound)