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

Error: [('PEM routines', 'PEM_read_bio', 'no start line')] #25

Open
kyale-mwendwa opened this issue Apr 10, 2018 · 2 comments · May be fixed by #44
Open

Error: [('PEM routines', 'PEM_read_bio', 'no start line')] #25

kyale-mwendwa opened this issue Apr 10, 2018 · 2 comments · May be fixed by #44

Comments

@kyale-mwendwa
Copy link

Hi I have run into a brick wall trying to get the wagtail anayltics to work. Followed the instructions on the page and I keep getting the following error while running it.

`[10/Apr/2018 15:53:41] "GET /admin/analytics/dashboard/ HTTP/1.1" 200 10119
Internal Server Error: /admin/analytics/token/
Traceback (most recent call last):
File "E:\Python27\lib\site-packages\django\core\handlers\exception.py", line 42, in inner
response = get_response(request)

File "E:\Python27\lib\site-packages\django\core\handlers\base.py", line 249, in _legacy_get_response
response = self._get_response(request)

File "E:\Python27\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)

File "E:\Python27\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "E:\Python27\lib\site-packages\django\views\decorators\cache.py", line 43, in _cache_controlled
response = viewfunc(request, *args, **kw)

File "E:\Python27\lib\site-packages\wagtail\wagtailadmin\decorators.py", line 24, in decorated_view
return view_func(request, *args, **kwargs)

File "E:\Python27\lib\site-packages\django\utils\decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)

File "E:\Python27\lib\site-packages\wagalytics\views.py", line 41, in token
access_token = get_access_token_from_str(settings.GA_KEY_CONTENT)

File "E:\Python27\lib\site-packages\wagalytics\views.py", line 33, in get_access_token_from_str
keyDict, SCOPE)

File "E:\Python27\lib\site-packages\oauth2client\service_account.py", line 264, in from_json_keyfile_dict
revoke_uri=revoke_uri)

File "E:\Python27\lib\site-packages\oauth2client\service_account.py", line 196, in _from_parsed_json_keyfile
signer = crypt.Signer.from_string(private_key_pkcs8_pem)

File "E:\Python27\lib\site-packages\oauth2client_openssl_crypt.py", line 119, in from_string
pkey = crypto.load_privatekey(crypto.FILETYPE_PEM, parsed_pem_key)

File "E:\Python27\lib\site-packages\OpenSSL\crypto.py", line 2795, in load_privatekey
_raise_current_error()

File "E:\Python27\lib\site-packages\OpenSSL_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)

Error: [('PEM routines', 'PEM_read_bio', 'no start line')]

[10/Apr/2018 15:53:45] "GET /admin/analytics/token/ HTTP/1.1" 500 18756`

@danielmwai
Copy link

kleberbaum added a commit to kleberbaum/wagalytics that referenced this issue Apr 30, 2020
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' has 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
kleberbaum added a commit to kleberbaum/wagalytics that referenced this issue Apr 30, 2020
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' has 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
kleberbaum added a commit to kleberbaum/wagalytics that referenced this issue Apr 30, 2020
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
@kleberbaum kleberbaum linked a pull request Apr 30, 2020 that will close this issue
6 tasks
@cspollar
Copy link
Contributor

Until a fix is merged, editing the private key solves this issue. I've replaced \nwith\n. For local testing I've hardcoded these values in my settings.py`.

# Sensitive Data Replaced with placeholder data.

GA_KEY_CONTENT = '{\
    "type": "service_account",\
    "project_id": "SOME-PROJECT-ID-123",\
    "private_key_id": "123",\
    "private_key": "-----BEGIN PRIVATE KEY-----\\n000000\\n111111\\n2222222\\n-----END PRIVATE KEY-----\\n",\
    "client_email": "[email protected]",\
    "client_id": "123",\
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",\
    "token_uri": "https://oauth2.googleapis.com/token",\
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",\
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/EXAMPLE"\
}'
GA_VIEW_ID = 'ga:123'

These

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

Successfully merging a pull request may close this issue.

3 participants