Developer

last person joined: 21 hours ago 

Expand all | Collapse all

Bad Request 400 when using REST api

This thread has been viewed 9 times
  • 1.  Bad Request 400 when using REST api

    Posted Jun 05, 2020 04:22 AM

    Hi,

    For the last couple of days my REST sessions dont work anymore.
    Within Ansible i use the aos_switch/login_switch.yml module.
    This has always worked, but for some reason it stopped a couple of days ago. The answer i get from the switch: Bad Request 400. The REST session timed out. Please login.

    Switch AOS version: WC.16.09.0010

    Aruba 2930


    I am sure that:

    - Switch is powerd on and i can reach it

    - Flashed new firmware (WC.16.09.0010)
    - IP is correct
    - username and password are correct ( i can login via ssh)
    - Ansible can access the module i use

    - Rest interace is enabled and is functioning

     

     

     REST Interface - Server Configuration
    
      REST Interface            : Enabled
      REST Operational Status   : Up
      REST Session Idle Timeout : 600 seconds
      HTTP Access               : Enabled
      HTTPS Access              : Disabled

     

     

     

    For the test case i use http and i updated the url accordantly.

     

     

    {
        "content": "<HTML><TITLE>400 Bad Request</TITLE><H1>Bad Request</H1>Please login to access the resource.<P></HTML>",
        "redirected": false,
        "url": "http://172.31.254.236/rest/v4/login-sessions",
        "status": 400,
        "server": "eHTTP v2.0",
        "connection": "close",
        "content_type": "text/html",
        "content_length": "102",
        "msg": "Status code was 400 and not [201]: HTTP Error 400: Bad Request",
        "elapsed": 0,
        "changed": false,
        "invocation": {
            "module_args": {
                "url": "http://172.31.254.236/rest/v4/login-sessions",
                "method": "POST",
                "headers": {
                    "Accept": "application/json",
                    "Content-Type": "application/json"
                },
                "body": {
                    "userName": "manager",
                    "password": 1234567
                },
                "body_format": "json",
                "validate_certs": false,
                "status_code": [
                    "201"
                ],
                "force": false,
                "http_agent": "ansible-httpget",
                "use_proxy": true,
                "force_basic_auth": false,
                "return_content": false,
                "follow_redirects": "safe",
                "timeout": 30,
                "follow": false,
                "url_username": null,
                "url_password": null,
                "client_cert": null,
                "client_key": null,
                "dest": null,
                "src": null,
                "creates": null,
                "removes": null,
                "unix_socket": null,
                "mode": null,
                "owner": null,
                "group": null,
                "seuser": null,
                "serole": null,
                "selevel": null,
                "setype": null,
                "attributes": null,
                "content": null,
                "backup": null,
                "remote_src": null,
                "regexp": null,
                "delimiter": null,
                "directory_mode": null,
                "unsafe_writes": null
            }
        },

     

     

     I cant login and register a session. So most of the playbooks i made dont work anymore.

    The login_switch.yml file looks as follows:

     

     

    - name: Login to {{ ansible_host }} {{ ansible_user }}
      uri:
        url: "http://{{ ansible_host }}/rest/v4/login-sessions"
        method: POST
        headers:
          Accept: "application/json"
          Content-Type: "application/json"
        body: {"userName": "{{ ansible_user }}", "password": "{{ ansible_password }}"}
        body_format: json
        validate_certs: no
        status_code: 201
      register: switch_session

     

     

     

    What is wrong and why do i get a bad request 400.

    The variables i pass with this playbook are:

     

    ansible_host: 172.31.254.236
    hostname: tsb
    ansible_user: manager
    ansible_password: 1234567
    ansible_connection: local  # Do not change
    ansible_network_os: arubaoss  # Do not change

     



  • 2.  RE: Bad Request 400 when using REST api

    MVP GURU
    Posted Jun 05, 2020 05:52 AM

    Hi,

     

    Do you have check the log ? there is also a limit of number of REST session if remember