oncall icon indicating copy to clipboard operation
oncall copied to clipboard

TypeError when executing user_sync.py via python3

Open dk0r opened this issue 5 years ago • 3 comments
trafficstars

Issue

Executing the LDAP user_sync.py script via [email protected] results in the following error: TypeError: a bytes-like object is required, not 'str' (full output shown here)

Expected Behavior

As described here, it is expected that the user_sync.py script should periodically sync users from a preexisting LDAP server

Steps to reproduce

Migrate [email protected] to python3. Step-by-step instructions for getting oncall running via py3 are published here

Troubleshooting attempts:

  • I'm not a python dev but google indicates the above error may be due to an upstream issue w/ gevent running on py3. Apparently something in gevent may need to be encoded to a bytes object via .encode('utf-8') 🤷🏻‍♂️
  • Posted issue to irisoncall's gitter

@diegocepedaw @dwang159

dk0r avatar Aug 25 '20 13:08 dk0r

looks like a bug in ldap_sync.py, can you try changing slack = mail.split('@')[0] to slack = mail.decode().split('@')[0]?

houqp avatar Aug 26 '20 07:08 houqp

@houqp thanks for the prompt reply!

Per your advice, I received a new IndexError when performing the following steps:

  1. Modified line-149 of ldap_sync.py to show as:
 slack = mail.decode().split('@')[0]
  1. Executed the user_sync.py script via the cli (while passing in my own config.yaml) as shown below:
# ./user_sync.py /home/oncall/configs/config.yaml
  1. Received the following IndexError (see full output here):
  File "/home/oncall/src/oncall/user_sync/ldap_sync.py", line 161, in fetch_ldap
    cookie = pctrls[0].cookie
IndexError: list index out of range
Troubleshooting steps:

As a non-python dev, the above IndexError indicates to me that pctrls[] does not contain a zero'th index, thus pctrls[0] DNE. Under this assumption, I did the following:

  1. Verified on line-158 that each element in pctrls[ ] corresponds to elements from serverctrls

  2. Verified on line-120 that each element in serverctrls corresponds to elements in req_ctrl

  3. Verified on line-106 that req_ctrl corresponds to the output of the SimplePagedResultsControl( ) method, which takes, as an input, a statically assigned empty cookie string (i.e. cookie='')

  4. Since the cookie being passed into SimplePagedResultsControl appears to always be empty, I unintelligibly tried modifying size (aka the page size) from line-106 to also be empty (i.e. size=0) as shown below:

    req_ctrl = SimplePagedResultsControl(True, size=0, cookie='')

  5. I then received the following error (see full output here):

sqlalchemy.exc.ProgrammingError: (pymysql.err.ProgrammingError) (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1")
[SQL: SELECT name FROM user WHERE active = FALSE AND name IN %s]
[parameters: (set(),)]
(Background on this error at: http://sqlalche.me/e/13/f405)

Any suggestions for further debug? My oncall container is using [email protected]

dk0r avatar Aug 31 '20 18:08 dk0r

It's possible that you didn't get any result from the ldap search, what did you get for the following logging call?

logger.info('Loaded %d entries from ldap.' % len(rdata))

houqp avatar Sep 09 '20 03:09 houqp