question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

clearer instructions in the Swagger API Docs how to set the CSRF token

See original GitHub issue

Motivation

I’ve been trying to get started with a basic empty apache superset… and add a single data source (Postgresql). So far I accidentally started wiring it via superset -set-database-uri which I later learned will change my apache supersets backend… not start examining my data… no problem I start switching to the REST api… but then I get stuck on the create database step because of CSRF

Proposed Change

On the Swagger API docs (and perhaps the part around superset -set-database-uri make it cleaer what we’re doing with databases… even just a simple prompt in the superset --help telling me to go examine the REST api can clue me in … in places where I should not be trying to use the CLI

New or Changed Public Interfaces

In the Swagger Docs I just need to know where or how to set the CSRF token… I am almost there but… just not sure where FLASK is expecting to find the CSRF token… so I just get constant 400 errors when trying to create my first DB

Traceback (most recent call last):
  File "/scratch.py", line 96, in <module>
    response = create_db_connection(jwt_token=bearer_tokens['access_token'], db_ip=db_host, db_port=db_port, username=db_user, password=db_password, db_name=db_name)
  File "/scratch.py", line 43, in create_db_connection
    response.raise_for_status()
  File "/home/emcp/anaconda3/envs//lib/python3.9/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: BAD REQUEST for url: http://someip:8088/api/v1/database/

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nytaicommented, Aug 5, 2021

closing this for now as it seems the core issue is resolved

0reactions
EMCPcommented, Aug 1, 2021

Closing issue is okay from my side…

I now have a working JSON to pass which seems to get a good test connection on POSTGresQL

    data_out = {
      "allow_csv_upload": True,
      "allow_ctas": False,
      "allow_cvas": False,
      "allow_dml": False,
      "allow_multi_schema_metadata_fetch": False,
      "allow_run_async": False,
      "cache_timeout": 0,
      "database_name": db_name,
      "expose_in_sqllab": True,
      "impersonate_user": False,
      "sqlalchemy_uri": sqlalchemy_url
    }

i got a 400 trying to nest another JSON object for default parameters… and when I tried to pass a blank one it gave a 500

    params_str = json.dumps({
        "metadata_params": {},
        "engine_params": {},
        "metadata_cache_timeout": {},
        "schemas_allowed_for_csv_upload": []
        })

    data_out = {
      "allow_csv_upload": True,
      "allow_ctas": False,
      "allow_cvas": False,
      "allow_dml": False,
      "allow_multi_schema_metadata_fetch": False,
      "allow_run_async": False,
      "cache_timeout": 0,
      "database_name": db_name,
      "expose_in_sqllab": True,
      "impersonate_user": False,
      "sqlalchemy_uri": sqlalchemy_url,
      "parameters": params_str
    }
Connected to pydev debugger (build 212.4746.96)
Traceback (most recent call last):
  File "/home/emcp/Tools/pycharm-community-2021.1.1/plugins/python-ce/helpers/pydev/pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/emcp/Tools/pycharm-community-2021.1.1/plugins/python-ce/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/scratch.py", line 81, in <module>
    create_response = create_db_connection(session, bearer_token=json.loads(response.text)['access_token'], csrf_token=json.loads(csrf_response.text)['result'], db_ip=db_host, db_port=db_port, db_user=db_user, db_pass=db_password, db_name=db_name)
  File "/scratch.py", line 44, in create_db_connection
    response.raise_for_status()
  File "/home/emcp/anaconda3/envs//lib/python3.9/site-packages/requests/models.py", line 943, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: http://SOMEIP:8088/api/v1/database/
python-BaseException
Read more comments on GitHub >

github_iconTop Results From Across the Web

CSRF support not working or not clear · Issue #892 - GitHub
Describe the bug springdoc.swagger-ui.csrf.enabled: true. Does not works as expected - expect pair header/will be added each request.
Read more >
Swagger-UI: Add CSRF-Cookie to all requests - Stack Overflow
Now I want to document this API using OpenAPI/Swagger. All routes are protected by a middleware that verifies the CSRF-Token, except for / ......
Read more >
CORS - Swagger Documentation
CORS is a technique to prevent websites from doing bad things with your personal data. Most browsers + JavaScript toolkits not only support...
Read more >
AC2 REST API how to use csrfToken? - Ubiquiti Community
I'm using AC2 REST API. I can succesfully login using POST (url /login). The answer is different from the SWAGGER UI documentation (it...
Read more >
Using the CSRF Token | SAP Help Portal
The server generates a token, stores it in the user's session table, and sends the value in the X-CSRF-Token HTTP response header. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found