LDAP ; error_handling [-] API call failed: expected string or buffer

I was able to get ldap to grant access, but I am seeing this error now:

2019-10-30 17:12:39,592 140168075161424 AUDIT access [-] Access granted to "e390084" with the token set to expire at "2019-10-31T17:12:39.590051Z". (username='e390084',token_expiration='2019-10-31T17:12:39.590051Z')
2019-10-30 17:12:39,593 140168075161424 DEBUG router [-] Using response spec "201" for endpoint st2auth.controllers.v1.auth:token_controller.post and status code 201
2019-10-30 17:12:39,593 140168075161424 ERROR error_handling [-] API call failed: expected string or buffer


Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/error_handling.py", line 48, in __call__
    return self.app(environ, start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/router.py", line 595, in as_wsgi
    return resp(environ, start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/webob/response.py", line 1305, in __call__
    start_response(self.status, headerlist)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/cors.py", line 84, in custom_start_response
    return start_response(status, headers._items, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/logging.py", line 88, in custom_start_response
    return start_response(status, headers, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/instrumentation.py", line 146, in custom_start_response
    return start_response(status, headers, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/request_id.py", line 48, in custom_start_response
    return start_response(status, headers._items, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 253, in start_response
    self.process_headers(headers)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 265, in process_headers
    if HEADER_VALUE_RE.search(value):
TypeError: expected string or buffer (_exception_data={},_exception_class='TypeError',_exception_message=u'expected string or buffer')
[2019-10-30 17:12:39 +0000] [24224] [ERROR] Error handling request /v1/tokens
Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/gunicorn/workers/base_async.py", line 56, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/gunicorn/workers/base_async.py", line 107, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/instrumentation.py", line 120, in __call__
    return self.app(environ, start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/request_id.py", line 50, in __call__
    return self.app(environ, custom_start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/instrumentation.py", line 148, in __call__
    return self.app(environ, custom_start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/logging.py", line 90, in __call__
    retval = self.app(environ, custom_start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/cors.py", line 89, in __call__
    return self.app(environ, custom_start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/error_handling.py", line 109, in __call__
    return resp(environ, start_response)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/webob/response.py", line 1305, in __call__
    start_response(self.status, headerlist)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/cors.py", line 84, in custom_start_response
    return start_response(status, headers._items, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/logging.py", line 88, in custom_start_response
    return start_response(status, headers, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/instrumentation.py", line 146, in custom_start_response
    return start_response(status, headers, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/middleware/request_id.py", line 48, in custom_start_response
    return start_response(status, headers._items, exc_info)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/gunicorn/http/wsgi.py", line 241, in start_response
    raise AssertionError("Response headers already set!")
AssertionError: Response headers already set!

It ended up being I was missing the

api_url

property of the auth config in

/etc/st2/st2.conf

Glad to hear you got it resolved.

In the future it would also help if you report which LDAP backend you use - open source one, or officially supported proprietary one which is part of EWC (aka proprietary paid version).

I will also open an issue to make sure we throw a more user-friendly error in such scenario if “api_url” config option is not set.

I opened a bug fix for that - Fix a bug with authentication API endpoint returning internal server error under gunicorn if auth.api_url config option was not set by Kami · Pull Request #4809 · StackStorm/st2 · GitHub.

The issue is not actually related to LDAP backend in any way.

That API endpoint would always return internal server error when running under gunicorn without “auth.api_url” config option being set.