Home > OS >  Python Rest API, how to sign in to retieve data
Python Rest API, how to sign in to retieve data

Time:02-25

I am trying to access a dataset from python available enter image description here

In the API documentation, there is no information on how to sign in using username and password via script. Upon manually entering the API URL into a browser

https://ev.caltech.edu/api/v1/sessions/caltech/ts

I have to manually enter the username: DEMO_TOKEN and password: <blank> and click on sign in to get the JSON response from the server. enter image description here

How do I programmatically do that in python?

Below is my snippet which doesn't work

import requests
api_url = "https://ev.caltech.edu/api/v1/sessions/caltech/ts"
response = requests.get(api_url)

response.json()

CodePudding user response:

Works for me, when I do this:

import requests
user = "DEMO_TOKEN"
passwd = ""
api_url = "https://ev.caltech.edu/api/v1/sessions/caltech/ts"
response = requests.get(api_url, auth=(user,passwd))
if response.status_code == 200:
    print(response.json())

Please be warned, the json is HUGE.

  • Related