rahul149386 commented on issue #20655:
URL: https://github.com/apache/superset/issues/20655#issuecomment-1181719031
I'm using couple of methods to import superset dashboard but I'm getting
failed. Anyone kindly have a look into this.
Method1: Using Request :
session = requests.session()
r = session.post(base_url + '/api/v1/security/login', json=payload)
access_token = r.json()
headersAuth = {
'Authorization': 'Bearer ' + access_token['access_token']
}
csrf_token = requests.get(
url=base_url+'/api/v1/security/csrf_token/',
headers=headersAuth
).json()["result"]
data = {
'username': 'admin',
'password': 'password',
'csrf_token':csrf_token
}
session.post(f'{base_url}/login/', data=data)
cookies=dict(session.cookies)
cookies=cookies['session']
dashboard_path='dashboard_path'
import_url=base_url+'/api/v1/dashboard/import/'
headers = {
'accept': 'application/json',
'Authorization':headersAuth['Authorization'],
'X-CSRFToken': csrf_token,
'Cookies':f'Session={cookies[1:]}',
'Referer': import_url
}
files = {
'formData': (
dashboard_path,
open(dashboard_path, 'r'),
'application/json'
)
}
response = requests.post(import_url, files=files, headers=headers)
print(response)
session.close()
Eroor:
Getting an Response 200 but unable to see the dashboard in the superset

Method2: Running a Curl though python
lst1=f'curl --location --request POST {import_url}\ -H
"X-CSRFToken:{csrf_token}"\ -H "Authorization:{Authorization}"\ -H
"Cookie:session={cookies}"\--form "formData=@"{dashboard_path}""\ --form
"overwrite="true"'
args = lst1.split(maxsplit=-1)
print(args)
process =
subprocess.Popen(args,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
stdout,stderr= process.communicate()
Error:
Could not resolve host:\ncurl: (3) URL using bad/illegal format or missing
URL\n'
Anyone responses will be apprciated.
--
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]