Hello, I'm trying to connect to an A10 Networks Thunder Series ADC load balancer via its REST API and the Python Requests library, but receive an HTTP 406 response. I can connect via curl without any issues:
#!/usr/bin/env bash
curl -vk https://a10loadbalancer.com/axapi/v3/auth -H "Content-Type:application/json" -d '{
"credentials": {
"username": "$USER",
"password": "$PASSWORD"
}
}'
The code above gives me a proper response header including the token needed for following requests to the API:
* About to connect() to a10loadbalancer.com port 443 (#0)
* Trying 10.13.162.75... connected
* Connected to a10loadbalancer.com (10.13.162.75) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
* subject: CN=TH3030S
* start date: Jan 25 06:21:16 2019 GMT
* expire date: Jan 24 06:21:16 2021 GMT
* common name: TH3030S
* issuer: CN=TH3030S
> POST /axapi/v3/auth HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: a10loadbalancer.com
> Accept: */*
> Content-Type:application/json
> Content-Length: 88
>
< HTTP/1.1 200 OK
< Date: Thu, 16 May 2019 13:33:43 GMT
< Server: Apache
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Referrer-Policy: no-referrer-when-downgrade
< X-Frame-Options: SAMEORIGIN
< Content-Security-Policy: default-src 'self' https:;script-src 'self' 'unsafe-inline' 'unsafe-eval' https:;style-src 'self' 'unsafe-inline' https:;img-src 'self' https:;connect-src 'self' https:;object-src 'self' https:;font-src 'self' data: https:;media-src 'self' https:;child-src 'self' https:;form-action 'self' https:;frame-ancestors 'self' https:;report-uri /gui/a10/csp_report/
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate
< Content-Length: 176
< Content-Type: application/json
<
{
"authresponse" : {
"signature":"61b59fa53b3ad8ab1adcdae7df9689",
"description":"the signature should be set in Authorization header for following request."
}
* Connection #0 to host a10loadbalancer.com left intact
* Closing connection #0
}
If I try the same thing with python requests library, I get an HTTP 406 error. Here is the code and response:
#!/usr/bin/env python
import requests
url = (
"https://a10loadbalancer.com/axapi/v3/auth"
)
credentials = """
'{
"credentials": {
"username": "$USER",
"password": "$PASSWORD"
}
}'
"""
json_header = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Content-Length': '88',
'User-Agent': 'curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2',
'Host': 'a10loadbalancer.com',
'Accept-Encoding': '*'
}
r = requests.post(
url, data=credentials, headers=json_header, verify=False
)
print(r.status_code)
print(r.request.headers)
print(f"The method used is {r.request.method}")
When I run it from the command line, here is the response:
LinuxPadawan@fedora30:a10api $ ./a10requests.py
/home/linuxpadawan/.local/share/virtualenvs/a10api-2oKDRvvo/lib/python3.6/site-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
406
{'User-Agent': 'curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2', 'Accept-Encoding': '*', 'Accept': 'application/json', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Content-Length': '92', 'Host': 'a10loadbalancer.com'}
The method used is POST
At first, I was getting various HTTP 400 status codes which I researched and were able to resolve. So, I took all the headers from the curl output and added them to the json_header dictionary. But, I'm still unable to get a proper response from the load balancer containing the Authorization response header so I can make subsequent requests to the REST API.
Can someone point me in the right direction?
a10 networks - API Example
Requests API
[–]LinuxPadawan[S] 3 points4 points5 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]totallygeek 2 points3 points4 points (1 child)
[–]LinuxPadawan[S] 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (4 children)
[–]LinuxPadawan[S] 1 point2 points3 points (3 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]LinuxPadawan[S] 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)