{"action":"created","comment":{"url":"https://api.github.com/repos/begriffs/postgrest/pulls/comments/48605490","id":48605490,"diff_hunk":"@@ -0,0 +1,49 @@\n+## Accessing PostgREST API using Python Requests and Requests-JWT\n+\n+This code relies on setting up the PostgreSQL auth functions and grants correctly first. Follow these instructions:\n+\n+http://postgrest.com/examples/users/\n+\n+After completing the configuration, be sure to create a user with email, password, role, and verified flag. We'll use that user to login in the code below.\n+\n+Install the required libraries\n+\n+    pip install requests\n+    pip install requests-jwt\n+\n+Then, from a python interpreter or script:\n+\n+    import requests\n+    import requests_jwt\n+    import json\n+\n+    # email and password auth through postgrest\n+    resp = requests.post('http://localhost:3000/rpc/login', json={\"email\": \"you@yours.com\", \"pass\": \"dog\"})\n+    if resp.status_code != 200:\n+        raise Exception()\n+\n+    # JWT auth using the token above\n+    token = json.loads(resp.text)['token']\n+    auth = requests_jwt.JWTAuth(token)\n+    if r.status_code != 200:\n+        raise Exception()\n+\n+    # Make a request to get the range header\n+    r = requests.get('http://localhost:3000/posts', auth=auth)","path":"docs/examples/python-requests-jwt.md","position":32,"original_position":32,"commit_id":"70ff55c8dad85496d5fe6abf29c4d43d334063b3","original_commit_id":"70ff55c8dad85496d5fe6abf29c4d43d334063b3","user":{"login":"davidthewatson","id":150892,"avatar_url":"https://avatars.githubusercontent.com/u/150892?v=3","gravatar_id":"","url":"https://api.github.com/users/davidthewatson","html_url":"https://github.com/davidthewatson","followers_url":"https://api.github.com/users/davidthewatson/followers","following_url":"https://api.github.com/users/davidthewatson/following{/other_user}","gists_url":"https://api.github.com/users/davidthewatson/gists{/gist_id}","starred_url":"https://api.github.com/users/davidthewatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidthewatson/subscriptions","organizations_url":"https://api.github.com/users/davidthewatson/orgs","repos_url":"https://api.github.com/users/davidthewatson/repos","events_url":"https://api.github.com/users/davidthewatson/events{/privacy}","received_events_url":"https://api.github.com/users/davidthewatson/received_events","type":"User","site_admin":false},"body":"@begriffs I've redone this entire thing minimizing all of the problems with the existing interface here:\r\n\r\nhttps://github.com/davidthewatson/postgrest_python_requests_client\r\n\r\nI'd be happy to redo this documentation based on that example. Thoughts?","created_at":"2015-12-30T14:13:40Z","updated_at":"2015-12-30T14:13:40Z","html_url":"https://github.com/begriffs/postgrest/pull/435#discussion_r48605490","pull_request_url":"https://api.github.com/repos/begriffs/postgrest/pulls/435","_links":{"self":{"href":"https://api.github.com/repos/begriffs/postgrest/pulls/comments/48605490"},"html":{"href":"https://github.com/begriffs/postgrest/pull/435#discussion_r48605490"},"pull_request":{"href":"https://api.github.com/repos/begriffs/postgrest/pulls/435"}}},"pull_request":{"url":"https://api.github.com/repos/begriffs/postgrest/pulls/435","id":54337196,"html_url":"https://github.com/begriffs/postgrest/pull/435","diff_url":"https://github.com/begriffs/postgrest/pull/435.diff","patch_url":"https://github.com/begriffs/postgrest/pull/435.patch","issue_url":"https://api.github.com/repos/begriffs/postgrest/issues/435","number":435,"state":"open","locked":false,"title":"Document python requests jwt","user":{"login":"davidthewatson","id":150892,"avatar_url":"https://avatars.githubusercontent.com/u/150892?v=3","gravatar_id":"","url":"https://api.github.com/users/davidthewatson","html_url":"https://github.com/davidthewatson","followers_url":"https://api.github.com/users/davidthewatson/followers","following_url":"https://api.github.com/users/davidthewatson/following{/other_user}","gists_url":"https://api.github.com/users/davidthewatson/gists{/gist_id}","starred_url":"https://api.github.com/users/davidthewatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidthewatson/subscriptions","organizations_url":"https://api.github.com/users/davidthewatson/orgs","repos_url":"https://api.github.com/users/davidthewatson/repos","events_url":"https://api.github.com/users/davidthewatson/events{/privacy}","received_events_url":"https://api.github.com/users/davidthewatson/received_events","type":"User","site_admin":false},"body":"As discussed with @begriffs, this example documents:\r\n\r\n* logging into a PostgREST API using python-requests\r\n* obtain token from response\r\n* use token auth with requests-jwt\r\n* use Range header for pagination of results","created_at":"2015-12-22T06:27:35Z","updated_at":"2015-12-30T14:13:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fddd1762f3118acdf45471e5ed08762ec3670d5d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/begriffs/postgrest/pulls/435/commits","review_comments_url":"https://api.github.com/repos/begriffs/postgrest/pulls/435/comments","review_comment_url":"https://api.github.com/repos/begriffs/postgrest/pulls/comments{/number}","comments_url":"https://api.github.com/repos/begriffs/postgrest/issues/435/comments","statuses_url":"https://api.github.com/repos/begriffs/postgrest/statuses/70ff55c8dad85496d5fe6abf29c4d43d334063b3","head":{"label":"davidthewatson:document-python-requests-jwt","ref":"document-python-requests-jwt","sha":"70ff55c8dad85496d5fe6abf29c4d43d334063b3","user":{"login":"davidthewatson","id":150892,"avatar_url":"https://avatars.githubusercontent.com/u/150892?v=3","gravatar_id":"","url":"https://api.github.com/users/davidthewatson","html_url":"https://github.com/davidthewatson","followers_url":"https://api.github.com/users/davidthewatson/followers","following_url":"https://api.github.com/users/davidthewatson/following{/other_user}","gists_url":"https://api.github.com/users/davidthewatson/gists{/gist_id}","starred_url":"https://api.github.com/users/davidthewatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidthewatson/subscriptions","organizations_url":"https://api.github.com/users/davidthewatson/orgs","repos_url":"https://api.github.com/users/davidthewatson/repos","events_url":"https://api.github.com/users/davidthewatson/events{/privacy}","received_events_url":"https://api.github.com/users/davidthewatson/received_events","type":"User","site_admin":false},"repo":{"id":48414132,"name":"postgrest","full_name":"davidthewatson/postgrest","owner":{"login":"davidthewatson","id":150892,"avatar_url":"https://avatars.githubusercontent.com/u/150892?v=3","gravatar_id":"","url":"https://api.github.com/users/davidthewatson","html_url":"https://github.com/davidthewatson","followers_url":"https://api.github.com/users/davidthewatson/followers","following_url":"https://api.github.com/users/davidthewatson/following{/other_user}","gists_url":"https://api.github.com/users/davidthewatson/gists{/gist_id}","starred_url":"https://api.github.com/users/davidthewatson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidthewatson/subscriptions","organizations_url":"https://api.github.com/users/davidthewatson/orgs","repos_url":"https://api.github.com/users/davidthewatson/repos","events_url":"https://api.github.com/users/davidthewatson/events{/privacy}","received_events_url":"https://api.github.com/users/davidthewatson/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/davidthewatson/postgrest","description":"REST API for any Postgres database","fork":true,"url":"https://api.github.com/repos/davidthewatson/postgrest","forks_url":"https://api.github.com/repos/davidthewatson/postgrest/forks","keys_url":"https://api.github.com/repos/davidthewatson/postgrest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/davidthewatson/postgrest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/davidthewatson/postgrest/teams","hooks_url":"https://api.github.com/repos/davidthewatson/postgrest/hooks","issue_events_url":"https://api.github.com/repos/davidthewatson/postgrest/issues/events{/number}","events_url":"https://api.github.com/repos/davidthewatson/postgrest/events","assignees_url":"https://api.github.com/repos/davidthewatson/postgrest/assignees{/user}","branches_url":"https://api.github.com/repos/davidthewatson/postgrest/branches{/branch}","tags_url":"https://api.github.com/repos/davidthewatson/postgrest/tags","blobs_url":"https://api.github.com/repos/davidthewatson/postgrest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/davidthewatson/postgrest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/davidthewatson/postgrest/git/refs{/sha}","trees_url":"https://api.github.com/repos/davidthewatson/postgrest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/davidthewatson/postgrest/statuses/{sha}","languages_url":"https://api.github.com/repos/davidthewatson/postgrest/languages","stargazers_url":"https://api.github.com/repos/davidthewatson/postgrest/stargazers","contributors_url":"https://api.github.com/repos/davidthewatson/postgrest/contributors","subscribers_url":"https://api.github.com/repos/davidthewatson/postgrest/subscribers","subscription_url":"https://api.github.com/repos/davidthewatson/postgrest/subscription","commits_url":"https://api.github.com/repos/davidthewatson/postgrest/commits{/sha}","git_commits_url":"https://api.github.com/repos/davidthewatson/postgrest/git/commits{/sha}","comments_url":"https://api.github.com/repos/davidthewatson/postgrest/comments{/number}","issue_comment_url":"https://api.github.com/repos/davidthewatson/postgrest/issues/comments{/number}","contents_url":"https://api.github.com/repos/davidthewatson/postgrest/contents/{+path}","compare_url":"https://api.github.com/repos/davidthewatson/postgrest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/davidthewatson/postgrest/merges","archive_url":"https://api.github.com/repos/davidthewatson/postgrest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/davidthewatson/postgrest/downloads","issues_url":"https://api.github.com/repos/davidthewatson/postgrest/issues{/number}","pulls_url":"https://api.github.com/repos/davidthewatson/postgrest/pulls{/number}","milestones_url":"https://api.github.com/repos/davidthewatson/postgrest/milestones{/number}","notifications_url":"https://api.github.com/repos/davidthewatson/postgrest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/davidthewatson/postgrest/labels{/name}","releases_url":"https://api.github.com/repos/davidthewatson/postgrest/releases{/id}","created_at":"2015-12-22T06:16:19Z","updated_at":"2015-12-22T06:16:19Z","pushed_at":"2015-12-22T20:16:11Z","git_url":"git://github.com/davidthewatson/postgrest.git","ssh_url":"git@github.com:davidthewatson/postgrest.git","clone_url":"https://github.com/davidthewatson/postgrest.git","svn_url":"https://github.com/davidthewatson/postgrest","homepage":"http://postgrest.com","size":2553,"stargazers_count":0,"watchers_count":0,"language":"Haskell","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"begriffs:master","ref":"master","sha":"437a592c65281afe100a2ab2b80d42c5064bee24","user":{"login":"begriffs","id":911911,"avatar_url":"https://avatars.githubusercontent.com/u/911911?v=3","gravatar_id":"","url":"https://api.github.com/users/begriffs","html_url":"https://github.com/begriffs","followers_url":"https://api.github.com/users/begriffs/followers","following_url":"https://api.github.com/users/begriffs/following{/other_user}","gists_url":"https://api.github.com/users/begriffs/gists{/gist_id}","starred_url":"https://api.github.com/users/begriffs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begriffs/subscriptions","organizations_url":"https://api.github.com/users/begriffs/orgs","repos_url":"https://api.github.com/users/begriffs/repos","events_url":"https://api.github.com/users/begriffs/events{/privacy}","received_events_url":"https://api.github.com/users/begriffs/received_events","type":"User","site_admin":false},"repo":{"id":20787122,"name":"postgrest","full_name":"begriffs/postgrest","owner":{"login":"begriffs","id":911911,"avatar_url":"https://avatars.githubusercontent.com/u/911911?v=3","gravatar_id":"","url":"https://api.github.com/users/begriffs","html_url":"https://github.com/begriffs","followers_url":"https://api.github.com/users/begriffs/followers","following_url":"https://api.github.com/users/begriffs/following{/other_user}","gists_url":"https://api.github.com/users/begriffs/gists{/gist_id}","starred_url":"https://api.github.com/users/begriffs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begriffs/subscriptions","organizations_url":"https://api.github.com/users/begriffs/orgs","repos_url":"https://api.github.com/users/begriffs/repos","events_url":"https://api.github.com/users/begriffs/events{/privacy}","received_events_url":"https://api.github.com/users/begriffs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/begriffs/postgrest","description":"REST API for any Postgres database","fork":false,"url":"https://api.github.com/repos/begriffs/postgrest","forks_url":"https://api.github.com/repos/begriffs/postgrest/forks","keys_url":"https://api.github.com/repos/begriffs/postgrest/keys{/key_id}","collaborators_url":"https://api.github.com/repos/begriffs/postgrest/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/begriffs/postgrest/teams","hooks_url":"https://api.github.com/repos/begriffs/postgrest/hooks","issue_events_url":"https://api.github.com/repos/begriffs/postgrest/issues/events{/number}","events_url":"https://api.github.com/repos/begriffs/postgrest/events","assignees_url":"https://api.github.com/repos/begriffs/postgrest/assignees{/user}","branches_url":"https://api.github.com/repos/begriffs/postgrest/branches{/branch}","tags_url":"https://api.github.com/repos/begriffs/postgrest/tags","blobs_url":"https://api.github.com/repos/begriffs/postgrest/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/begriffs/postgrest/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/begriffs/postgrest/git/refs{/sha}","trees_url":"https://api.github.com/repos/begriffs/postgrest/git/trees{/sha}","statuses_url":"https://api.github.com/repos/begriffs/postgrest/statuses/{sha}","languages_url":"https://api.github.com/repos/begriffs/postgrest/languages","stargazers_url":"https://api.github.com/repos/begriffs/postgrest/stargazers","contributors_url":"https://api.github.com/repos/begriffs/postgrest/contributors","subscribers_url":"https://api.github.com/repos/begriffs/postgrest/subscribers","subscription_url":"https://api.github.com/repos/begriffs/postgrest/subscription","commits_url":"https://api.github.com/repos/begriffs/postgrest/commits{/sha}","git_commits_url":"https://api.github.com/repos/begriffs/postgrest/git/commits{/sha}","comments_url":"https://api.github.com/repos/begriffs/postgrest/comments{/number}","issue_comment_url":"https://api.github.com/repos/begriffs/postgrest/issues/comments{/number}","contents_url":"https://api.github.com/repos/begriffs/postgrest/contents/{+path}","compare_url":"https://api.github.com/repos/begriffs/postgrest/compare/{base}...{head}","merges_url":"https://api.github.com/repos/begriffs/postgrest/merges","archive_url":"https://api.github.com/repos/begriffs/postgrest/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/begriffs/postgrest/downloads","issues_url":"https://api.github.com/repos/begriffs/postgrest/issues{/number}","pulls_url":"https://api.github.com/repos/begriffs/postgrest/pulls{/number}","milestones_url":"https://api.github.com/repos/begriffs/postgrest/milestones{/number}","notifications_url":"https://api.github.com/repos/begriffs/postgrest/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/begriffs/postgrest/labels{/name}","releases_url":"https://api.github.com/repos/begriffs/postgrest/releases{/id}","created_at":"2014-06-13T00:23:00Z","updated_at":"2015-12-30T10:09:26Z","pushed_at":"2015-12-29T21:07:27Z","git_url":"git://github.com/begriffs/postgrest.git","ssh_url":"git@github.com:begriffs/postgrest.git","clone_url":"https://github.com/begriffs/postgrest.git","svn_url":"https://github.com/begriffs/postgrest","homepage":"http://postgrest.com","size":2689,"stargazers_count":5979,"watchers_count":5979,"language":"Haskell","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":195,"mirror_url":null,"open_issues_count":60,"forks":195,"open_issues":60,"watchers":5979,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/begriffs/postgrest/pulls/435"},"html":{"href":"https://github.com/begriffs/postgrest/pull/435"},"issue":{"href":"https://api.github.com/repos/begriffs/postgrest/issues/435"},"comments":{"href":"https://api.github.com/repos/begriffs/postgrest/issues/435/comments"},"review_comments":{"href":"https://api.github.com/repos/begriffs/postgrest/pulls/435/comments"},"review_comment":{"href":"https://api.github.com/repos/begriffs/postgrest/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/begriffs/postgrest/pulls/435/commits"},"statuses":{"href":"https://api.github.com/repos/begriffs/postgrest/statuses/70ff55c8dad85496d5fe6abf29c4d43d334063b3"}}}}