oncall
oncall copied to clipboard
TypeError when executing user_sync.py via python3
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/
geventrunning on py3. Apparently something ingeventmay need to be encoded to a bytes object via.encode('utf-8')🤷🏻♂️ - Posted issue to irisoncall's gitter
@diegocepedaw @dwang159
looks like a bug in ldap_sync.py, can you try changing slack = mail.split('@')[0] to slack = mail.decode().split('@')[0]?
@houqp thanks for the prompt reply!
Per your advice, I received a new IndexError when performing the following steps:
- Modified line-149 of
ldap_sync.pyto show as:
slack = mail.decode().split('@')[0]
- Executed the
user_sync.pyscript via thecli(while passing in my ownconfig.yaml) as shown below:
# ./user_sync.py /home/oncall/configs/config.yaml
- 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:
-
Verified on line-158 that each element in
pctrls[ ]corresponds to elements fromserverctrls -
Verified on line-120 that each element in
serverctrlscorresponds to elements inreq_ctrl -
Verified on line-106 that
req_ctrlcorresponds to the output of the SimplePagedResultsControl( ) method, which takes, as an input, a statically assigned empty cookie string (i.e.cookie='') -
Since the cookie being passed into SimplePagedResultsControl appears to always be empty, I unintelligibly tried modifying
size(aka thepage size) from line-106 to also be empty (i.e.size=0) as shown below:req_ctrl = SimplePagedResultsControl(True, size=0, cookie='') -
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]
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))