Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

SystemError thrown with Python 3.10 #88

Open
stevenpackardblp opened this issue Sep 26, 2021 · 6 comments · May be fixed by #89
Open

SystemError thrown with Python 3.10 #88

stevenpackardblp opened this issue Sep 26, 2021 · 6 comments · May be fixed by #89

Comments

@stevenpackardblp
Copy link

When using the module with Python 3.10 in conjunction with requests-kerberos, a SystemError is thrown in the channelBindings function. This is the stack trace:

  File "/usr/lib/python3.10/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.10/site-packages/requests/sessions.py", line 662, in send
    r = dispatch_hook('response', hooks, r, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests/hooks.py", line 31, in dispatch_hook
    _hook_data = hook(hook_data, **kwargs)
  File "/usr/lib/python3.10/site-packages/requests_kerberos/kerberos_.py", line 415, in handle_response
    self.cbt_struct = kerberos.channelBindings(application_data=cbt_application_data)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

This is due to a behavioral change made in Python 3.10 which requires extension modules to use the Py_ssize_t type rather than the int type for string lengths:

The following patch resolves the issue:

--- a/src/kerberos.c
+++ b/src/kerberos.c
@@ -14,6 +14,7 @@
  * limitations under the License.
  **/

+#define PY_SSIZE_T_CLEAN
 #include <Python.h>

 #include "kerberosbasic.h"
@@ -244,9 +245,9 @@
     char *initiator_address = NULL;
     char *acceptor_address = NULL;
     char *application_data = NULL;
-    int initiator_length = 0;
-    int acceptor_length = 0;
-    int application_length = 0;
+    Py_ssize_t initiator_length = 0;
+    Py_ssize_t acceptor_length = 0;
+    Py_ssize_t application_length = 0;

     PyObject *pychan_bindings = NULL;
     struct gss_channel_bindings_struct *input_chan_bindings;
@hroncok
Copy link

hroncok commented Sep 29, 2021

I can confirm the attached patch fixes the issue.

@dreness
Copy link
Member

dreness commented Sep 29, 2021

Very thorough report, thanks!

@stevenpackardblp
Copy link
Author

Python 3.10 is officially releasing today. Shall I submit a Pull Request with my patch?

@stevenpackardblp stevenpackardblp linked a pull request Oct 25, 2021 that will close this issue
@stevenpackardblp
Copy link
Author

@dreness I went ahead and submitted a Pull Request. Now that Python 3.10 is officially released, this is becoming problematic for pip installations from PyPI. Please have a look. Thanks!

@FlorianHeigl
Copy link

just hit this on OSX with /usr/local/Cellar/ansible/5.2.0/libexec/bin/python3.10

@FlorianHeigl
Copy link

FlorianHeigl commented Feb 27, 2023

same on 3.11. by now on a M1 MacBook so a fully reinstalled homebrew tree.
Don't have kerberos installed, only pykerberos 1.2.4. Also checked that the sources are patched with stevenpackardblp 's patch. Maybe time to buy a dozen raspberrys with different virtual_envs.
it must all be joke. I don't care anymore.

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

Successfully merging a pull request may close this issue.

4 participants