Developer

 View Only
last person joined: yesterday 

Expand all | Collapse all

ArubaOS-Switch WC.16.10.0011 : cannot login with Python

This thread has been viewed 18 times
  • 1.  ArubaOS-Switch WC.16.10.0011 : cannot login with Python

    Posted Jan 23, 2021 11:15 AM
    Here's an example of script that works perfecty on WC.16.10.0002 , but not on WC.16.10.0011 :

    # https://arubaos-switch-rest-guide.readthedocs.io/en/latest/
    
    import re
    import requests
    import json
    
    # Use authentication call and pass credentials
    url="http://" + "x.x.x.x" + "/rest/v1/login-sessions"
    
    
    data = {"userName":"manager","password":"x"}
    
    r = requests.post(url, data=json.dumps(data), verify=False)
    
    
    # Parse token
    cookie = r.json()["cookie"].split("=")[1]
    print("Cookie: " + cookie)
    
    # Prepare JSON structure with ip address and token
    login = {"ip":"x.x.x.x","cookie":cookie}
    
    # Write JSON to file to be read by other scripts
    f = open('mylogin.txt', 'w')
    f.write(json.dumps(login))
    f.close


    I can log in with curl, but not with Python. No response, just shuts down the connection, I have tried with both requests and httpx.

    Any idea?
    thanks

    POST /rest/v7/login-sessions HTTP/1.1
    Host: x.x.x.x
    Accept: */*
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    User-Agent: python-httpx/0.16.1
    Content-Length: 48
    Content-Type: application/json
    
    {"userName": "manager", "password": "x"}


    ------------------------------
    J.
    ------------------------------


  • 2.  RE: ArubaOS-Switch WC.16.10.0011 : cannot login with Python

    EMPLOYEE
    Posted Jan 25, 2021 05:36 PM
    Hey Jose,

    Hmm, that is a really weird behavior that there is no response at all.

    What happens if you try replacing "v1" with "v7" in the URL creation line?

    url="http://" + "x.x.x.x" + "/rest/v1/login-sessions"​

    Thanks,
    Derek

    ------------------------------
    Derek Wang
    ------------------------------



  • 3.  RE: ArubaOS-Switch WC.16.10.0011 : cannot login with Python

    Posted Jan 28, 2021 05:46 PM
    Thanks @TwentyDW
    The problem seems to be a bug in 16.10.0011, as pointed out by alagoutte


    ------------------------------
    Jose Moreno
    ------------------------------



  • 4.  RE: ArubaOS-Switch WC.16.10.0011 : cannot login with Python
    Best Answer

    MVP GURU
    Posted Jan 26, 2021 06:55 AM
    Hi,

    Do you have check the log on the switch ?

    Can you update to 16.10.0012, there is fix about REST and PowerShell may be the same issue with python...

    ------------------------------
    PowerArubaSW : Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP...

    PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...)

    PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)..

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------



  • 5.  RE: ArubaOS-Switch WC.16.10.0011 : cannot login with Python

    Posted Jan 28, 2021 06:05 PM
    That's it! Thank you alagoutte!
    This has been nagging me for months! I wonder how this one slipped through FW testing.

    (Excuse my slightly frustrated tone. I do appreciate the help).


    ------------------------------
    Jose Moreno
    ------------------------------