You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/06/03 11:30:18 UTC

[GitHub] [superset] lmingzhi commented on issue #2488: How to authenticate with REST API

lmingzhi commented on issue #2488:
URL: https://github.com/apache/superset/issues/2488#issuecomment-1145870468

   Thank to [andrewsali](https://github.com/andrewsali) commented [on 18 Jan 2018](https://github.com/apache/superset/issues/2488#issuecomment-358429474), I finally figure out how to access the superset REST API by python code.
   
   ```
   import requests
   from bs4 import BeautifulSoup
   
   # https://192.168.100.120:8088/swagger/v1
   superset_host = '192.168.100.120:8088'
   username = 'YOUR_username'
   password = 'YOUR_password'
   
   # set up session for auth
   s = requests.Session()
   login_form = s.post(f"http://{superset_host}/login")
   # get Cross-Site Request Forgery protection token
   soup = BeautifulSoup(login_form.text, 'html.parser')
   csrf_token = soup.find('input',{'id':'csrf_token'})['value']
   data = {
       'username': username,
       'password': password,
       'csrf_token':csrf_token
   }
   # login the given session
   s.post(f'http://{superset_host}/login/', data=data)
   print(dict(s.cookies))
   
   url = f'http://{superset_host}/api/v1/chart/'
   r = s.get(url)
   print(r.json())
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org