Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when executing user_sync.py via python3 #319

Open
dk0r opened this issue Aug 25, 2020 · 3 comments
Open

TypeError when executing user_sync.py via python3 #319

dk0r opened this issue Aug 25, 2020 · 3 comments

Comments

@dk0r
Copy link

dk0r commented Aug 25, 2020

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

@houqp
Copy link
Contributor

houqp commented Aug 26, 2020

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

@dk0r
Copy link
Author

dk0r commented Aug 31, 2020

@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]

@houqp
Copy link
Contributor

houqp commented Sep 9, 2020

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))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants