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/10/27 14:09:41 UTC
[GitHub] [superset] 1c7 commented on issue #16398: Unable to use create database via API: `The CSRF token is missing.`
1c7 commented on issue #16398:
URL: https://github.com/apache/superset/issues/16398#issuecomment-1293583699
@lziosi Very helpful! works for me!
shorter example
```python
def add_dataset(database_id, schema: 'mp_analytic', table_name):
payload = {
"database": database_id, # 数据库的 ID
"schema": schema,
"table_name": table_name # 数据库表名
}
url = f"{base}/api/v1/dataset/"
session = requests.Session()
session.headers['Authorization'] = 'Bearer ' + get_access_token()
session.headers['Content-Type'] = 'application/json'
csrf_url = f"{base}/api/v1/security/csrf_token/"
csrf_res = session.get(csrf_url)
csrf_token = csrf_res.json()['result']
session.headers['Referer']= csrf_url
session.headers['X-CSRFToken'] = csrf_token
payload_json = json.dumps(payload)
r = session.post(url, data=payload_json)
return 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