From fee48c140fe86e65d4d14597d64997934f630b59 Mon Sep 17 00:00:00 2001 From: kleberbaum Date: Fri, 1 May 2020 00:42:22 +0200 Subject: [PATCH] Fix GA_KEY_CONTENT OpenSSL crypto error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenSSL.crypto.load_privatekey can't detect start line due to a str.replace() for '\n' and '\r'. json.loads() can't handle '\n' and '\r' cause it thinks they are control character. Therefore '\n' and '\r' have to be double escape rather than deleted. OpenSSL.crypto.load_privatekey() can't handle '\r' either, so a private_key with '\r' wouldn't work anyway. ¯\_(ツ)_/¯ Error: OpenSSL.crypto.Error: [('PEM routines', 'get_name', 'no start line')] Ref: tomdyson#25 https://stackoverflow.com/a/45571017 --- wagalytics/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wagalytics/views.py b/wagalytics/views.py index 8aeaaaf..d856a8a 100755 --- a/wagalytics/views.py +++ b/wagalytics/views.py @@ -54,7 +54,7 @@ def get_access_token_from_str(ga_key_content): SCOPE = 'https://www.googleapis.com/auth/analytics.readonly' # Construct a credentials objects from the key data and OAuth2 scope. - keyDict = json.loads(ga_key_content.replace('\n', '').replace('\r', '')) + keyDict = json.loads(ga_key_content.replace('\n', '\\n')) _credentials = ServiceAccountCredentials.from_json_keyfile_dict( keyDict, SCOPE)