JWTAssertionCredentials with service account fails with asn1 not enough data error

StackOverflow https://stackoverflow.com/questions/20942606

  •  24-09-2022
  •  | 
  •  

سؤال

When attempting to use SignedJwtAssertionCredentials() with a google service account I have been receiving the following error on one Windows 2008 server machine, but not on a Windows 7 machine locally.

Error: [('asn1 encoding routines', 'ASN1_D2I_READ_BIO', 'not enough data')]

I am reading the p12 key file as follows before passing it to SignedJwtAssertionCredentials().

    with open(path_to_key_file, 'r') as f:
        private_key = f.read()
هل كانت مفيدة؟

المحلول

The solution is to use binary mode when reading the file in this way. Note the 'b'

    with open(path_to_key_file, 'rb') as f:
        private_key = f.read()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top