UnhandledPromiseRejectionWarning: Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
Problem
I get the above error when I try initializing the drive with the jwt token. Below's my implementation. the keys are valid and I downloaded the file from the google developer console. [code block] `workDir` is a variable holding a reference to a string with the name of a working directory. The weird thing is that this was working last week but then it stopped working for some reason.
Error Output
error when I try initializing the drive with the jwt token. Below's my implementation.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix PEM_read_bio:no start line Error in JWT Initialization
The error 'PEM_read_bio:no start line' indicates that the PEM file being read does not start with the expected '-----BEGIN CERTIFICATE-----' or '-----BEGIN PRIVATE KEY-----' line. This can occur if the file is corrupted, incorrectly formatted, or if the path to the file is incorrect. Since the implementation was working previously, it is possible that the file was modified or replaced unintentionally.
Awaiting Verification
Be the first to verify this fix
- 1
Verify PEM File Format
Open the PEM file downloaded from the Google Developer Console and ensure it starts with the correct header. It should begin with '-----BEGIN PRIVATE KEY-----' for a private key or '-----BEGIN CERTIFICATE-----' for a certificate. If it does not, the file may be corrupted or incorrectly downloaded.
bashcat path/to/your/file.pem - 2
Check File Path
Ensure that the path to the PEM file in your code is correct. If the working directory has changed or the file has been moved, update the path accordingly.
typescriptconst keyFile = `${workDir}/path/to/your/file.pem`; - 3
Re-download the PEM File
If the PEM file is corrupted or incorrectly formatted, re-download it from the Google Developer Console. Make sure to select the correct credentials and download the file again.
- 4
Check for Extra Characters
Open the PEM file in a text editor and ensure there are no extra characters, spaces, or new lines before the '-----BEGIN' line or after the '-----END' line. Remove any such characters if present.
- 5
Test JWT Initialization
After verifying the PEM file and correcting any issues, attempt to initialize the drive with the JWT token again. Monitor for any errors during this process.
typescriptconst jwtClient = new JWT({ key: fs.readFileSync(keyFile), ... });
Validation
To confirm the fix worked, successfully initialize the Google Drive API with the JWT token without encountering the 'PEM_read_bio:no start line' error. You should be able to make API calls without issues.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep