For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Zdenda's avatar
Zdenda
Icon for Cirrus rankCirrus
Dec 28, 2015

API Rest token-based auth problem

This is continuation of discussion here

LB: Viprion vCMP Guest, version 11.5.2 1.23.169

Problem: when I run python script using code from article mentioned above (without any changes), I get following error:

 

C:\Python27>python auth_test.py 10.10.10.10 test_user testpool
test_user, enter your password: Password:
Traceback (most recent call last):
  File "auth_test.py", line 47, in 
    token = get_token(b, url_auth, (username, password))
  File "auth_test.py", line 14, in get_token
    token = bigip.post(url, json.dumps(payload)).json()['token']['token']
KeyError: 'token'

 

Do somebody know what can be the reason? I am suspecting line: token = bigip.post(url, json.dumps(payload)).json()['token']['token']

Thanks for any advise, Zdenek

4 Replies

  • Remove the ['token']['token'] from the end of that line and then add "print token" on the next line so you can evaluate the output. Feel free to edit your question with that output and I'll take a look at what's going on.
  • Hi Jason, I tried to remove ['token']['token'] and got following:

     

     {u'errorStack': [u'com.f5.rest.common.RestWorkerUriNotFoundException: http://localhost:8100/mgmt/shared/authn/login', u'at com.f5.rest.common.RestSer
    ver.trySendInProcess(RestServer.java:231)', u'at com.f5.rest.common.RestRequestReceiver.dispatchToService(RestRequestReceiver.java:93)', u'at com.f5.r
    est.common.RestRequestReceiver.processNext(RestRequestReceiver.java:57)', u'at com.f5.rest.common.RestHelper$2.run(RestHelper.java:1910)', u'at java.u
    til.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)', u'at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:615)', u'at java.lang.Thread.run(Thread.java:722)\n'], u'message': u'http://localhost:8100/mgmt/shared/authn/login', u'code': 404, u'restOperati
    onId': 4617544}
    
    Token: {u'errorStack': [u'com.f5.rest.common.RestWorkerUriNotFoundException: http://localhost:8100/mgmt/shared/authn/login', u'at com.f5.rest.common.R
    estServer.trySendInProcess(RestServer.java:231)', u'at com.f5.rest.common.RestRequestReceiver.dispatchToService(RestRequestReceiver.java:93)', u'at co
    m.f5.rest.common.RestRequestReceiver.processNext(RestRequestReceiver.java:57)', u'at com.f5.rest.common.RestHelper$2.run(RestHelper.java:1910)', u'at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)', u'at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolEx
    ecutor.java:615)', u'at java.lang.Thread.run(Thread.java:722)\n'], u'message': u'http://localhost:8100/mgmt/shared/authn/login', u'code': 404, u'restO
    perationId': 4617544}
    
    Traceback (most recent call last):
      File "auth_test.py", line 54, in 
        response = create_pool(b, url_pool, poolname)
      File "auth_test.py", line 5, in create_pool
        pool_config = bigip.post(url, json.dumps(payload)).json()
      File "C:\Python27\lib\requests\sessions.py", line 508, in post
        return self.request('POST', url, data=data, json=json, **kwargs)
      File "C:\Python27\lib\requests\sessions.py", line 465, in request
        resp = self.send(prep, **send_kwargs)
      File "C:\Python27\lib\requests\sessions.py", line 573, in send
        r = adapter.send(request, **kwargs)
      File "C:\Python27\lib\requests\adapters.py", line 370, in send
        timeout=timeout
      File "C:\Python27\lib\requests\packages\urllib3\connectionpool.py", line 544, in urlopen
        body=body, headers=headers)
      File "C:\Python27\lib\requests\packages\urllib3\connectionpool.py", line 349, in _make_request
        conn.request(method, url, **httplib_request_kw)
      File "C:\Python27\lib\httplib.py", line 946, in request
        self._send_request(method, url, body, headers)
      File "C:\Python27\lib\httplib.py", line 986, in _send_request
        self.putheader(hdr, value)
      File "C:\Python27\lib\httplib.py", line 924, in putheader
        str = '%s: %s' % (header, '\r\n\t'.join(values))
    TypeError: sequence item 0: expected string, dict found
    

     

    I tried to get rid of some error messages and removed calling of function "create_pool", but then I got only (no output from "print token" visible):

     

     {u'errorStack': [u'com.f5.rest.common.RestWorkerUriNotFoundException: http://localhost:8100/mgmt/shared/authn/login', u'at com.f5.rest.common.RestSer
    ver.trySendInProcess(RestServer.java:231)', u'at com.f5.rest.common.RestRequestReceiver.dispatchToService(RestRequestReceiver.java:93)', u'at com.f5.r
    est.common.RestRequestReceiver.processNext(RestRequestReceiver.java:57)', u'at com.f5.rest.common.RestHelper$2.run(RestHelper.java:1910)', u'at java.u
    til.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)', u'at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
    .java:615)', u'at java.lang.Thread.run(Thread.java:722)\n'], u'message': u'http://localhost:8100/mgmt/shared/authn/login', u'code': 404, u'restOperati
    onId': 4617823}
    
    Token: {u'errorStack': [u'com.f5.rest.common.RestWorkerUriNotFoundException: http://localhost:8100/mgmt/shared/authn/login', u'at com.f5.rest.common.R
    estServer.trySendInProcess(RestServer.java:231)', u'at com.f5.rest.common.RestRequestReceiver.dispatchToService(RestRequestReceiver.java:93)', u'at co
    m.f5.rest.common.RestRequestReceiver.processNext(RestRequestReceiver.java:57)', u'at com.f5.rest.common.RestHelper$2.run(RestHelper.java:1910)', u'at
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)', u'at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolEx
    ecutor.java:615)', u'at java.lang.Thread.run(Thread.java:722)\n'], u'message': u'http://localhost:8100/mgmt/shared/authn/login', u'code': 404, u'restO
    perationId': 4617823}
    

     

  • Hi, does somebody have the same problem? I tried couple of more tests, but am not able to get it working. Jason, if you read it, can you please post whether you have tested it on version 11.5.2 or only on v12? Thx Zdenek

     

    • JRahm's avatar
      JRahm
      Icon for Admin rankAdmin

      sorry to take so long to get back to you. As i stated earlier, if you removed the formatting on the token request and logged that, you'd see that that method is not supported in 11.5.2:

      {u'errorStack': [u'com.f5.rest.common.RestWorkerUriNotFoundException: http://localhost:8100/mgmt/shared/authn/login', u'at com.f5.rest.common.RestServer.trySendInProcess(RestServer.java:231)', u'at com.f5.rest.common.RestRequestReceiver.dispatchToService(RestRequestReceiver.java:93)', u'at com.f5.rest.common.RestRequestReceiver.processNext(RestRequestReceiver.java:57)', u'at com.f5.rest.common.RestHelper$2.run(RestHelper.java:1910)', u'at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)', u'at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)', u'at java.lang.Thread.run(Thread.java:722)\n'], u'message': u'http://localhost:8100/mgmt/shared/authn/login', u'code': 404, u'restOperationId': 6650}