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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to