平台之间对 apiclient 的相同调用是否崩溃

Identical call to apiclient crashes or not between platforms

我无法理解为什么以下代码在一个平台上运行 (Windows) 而在另一个平台上崩溃 (Raspbian Linux,一个 Raspberry Pi 版本的 Debian ).下面的代码通过 a Google API authentication:

import oauth2client.client
import httplib2
import platform
import apiclient

print(platform.python_version())
print((oauth2client.__version__, httplib2.__version__, apiclient.__version__))

with open('galarmclock.p12', 'rb') as f:
    private_key = f.read()

credentials = oauth2client.client.SignedJwtAssertionCredentials(
    'mail-from-api-console@developer.gserviceaccount.com',
    private_key,
    'https://www.googleapis.com/auth/calendar.readonly',
    sub='a-sub@example.com'
)
http_auth = credentials.authorize(httplib2.Http())
service = apiclient.discovery.build('calendar', 'v3', http=http_auth)
print(service)

在 Windows 8.1 上输出符合预期:

3.4.3
('1.5.1', '0.9.2', '1.4.2')
<googleapiclient.discovery.Resource object at 0x0380F530>

RPi 上的相同代码 运行 在 apiclient.discovery.build 调用时崩溃。

3.4.3+
('1.5.1', '0.9.2', '1.4.2')
Traceback (most recent call last):
  File "testauthgoogle.py", line 19, in <module>
    service = apiclient.discovery.build('calendar', 'v3', http=http_auth)
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/util.py", line 142, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/googleapiclient/discovery.py", line 196, in build
    cache)
  File "/usr/local/lib/python3.4/dist-packages/googleapiclient/discovery.py", line 242, in _retrieve_discovery_doc
    resp, content = http.request(actual_url)
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/client.py", line 565, in new_request
    self._refresh(request_orig)
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/client.py", line 835, in _refresh
    self._do_refresh_request(http_request)
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/client.py", line 862, in _do_refresh_request
    body = self._generate_refresh_request_body()
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/client.py", line 1541, in _generate_refresh_request_body
    assertion = self._generate_assertion()
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/client.py", line 1670, in _generate_assertion
    private_key, self.private_key_password), payload)
  File "/usr/local/lib/python3.4/dist-packages/oauth2client/_openssl_crypt.py", line 120, in from_string
    pkey = crypto.load_pkcs12(key, password).get_privatekey()
TypeError: must be str, not bytes

我不知道该往哪里走:Python 和库版本相同,但它们的行为不同。

问题出在 Rpi 上的 OpenSSL 版本 0.13 上。 0.15 Windows。

更新 OpenSSL 解决了这个问题,两个代码 运行 相同。