k6407399 opened a new issue, #23419:
URL: https://github.com/apache/superset/issues/23419
Hi There,
I am new here and new for Superset too.
I am using Superset Version : 0.38.1
While creating the Bulk users with the below script, I was facing the issue
like <Response [403]>
**My Code is Here**
import requests
from bs4 import BeautifulSoup as bs
from bs4 import Comment
import json
class UserSupersetApi:
def __init__(self, username=None, password=None):
self.s = requests.Session()
self.base_url = "http://localhost:8088/"
self._csrf = self._getCSRF(self.url('api/v1/security/login/'))
#login/
self.headers = {'X-CSRFToken': self._csrf, 'Referer':
self.url('api/v1/security/login/')} #login/
# note: does not use headers because of flask_wtf.csrf.validate_csrf
# if data is dict it is used as form and ends up empty but flask_wtf
checks if data ...
self.s.post(self.url('api/v1/security/login/'), #login/
data={'username': username, 'password': password, 'csrf_token':
self._csrf},
allow_redirects=False)
def url(self, url_path):
return self.base_url + url_path
def get(self, url_path):
return self.s.get(self.url(url_path), headers=self.headers)
def post(self, url_path, data=None, json_data=None, **kwargs):
kwargs.update({'url': self.url(url_path), 'headers': self.headers})
if data:
data['csrf_token'] = self._csrf
kwargs['data'] = data
if json_data:
kwargs['json'] = json_data
return self.s.post(**kwargs, allow_redirects=False)
def _getCSRF(self, url_path):
response = self.s.get(url_path)
soup = bs(response.content, "html.parser")
csrf_token = None # Initialize with a default value
for tag in soup.find_all('input', id='csrf_token'):
csrf_token = tag['value']
return csrf_token
## authenticate + set global vars
superset_username = 'admin'
superset_pw = 'admin'
superset = UserSupersetApi(superset_username, superset_pw)
users = [{
'first_name': 'Ravi',
'last_name':'Kumar',
'username': 'kondru',
'email': '[email protected]',
'conf_password': '12345',
'password': '12345',
'roles': ['10']
}]
for user in users:
payload = {'first_name': user['first_name'],
'last_name': user['last_name'],
'username': user['username'],
'email': user['email'],
'active': 'y', #also tried with True instead of y
'conf_password': user['password'],
'password': user['password'],
'roles': user['roles']
}
print(superset.post(url_path='users/add', json=payload,verify=False))
--
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]