未定义的符号:PyUnicodeUCS2_Decode

问题描述:

我正尝试使用gspread连接到我的谷歌床单。下面是代码:未定义的符号:PyUnicodeUCS2_Decode

#IMPORT STANDARD LIBRARIES 
import json 
import os 

#IMPORT THIRD PARTY LIBRARIES 
import gspread 
from oauth2client.client import SignedJwtAssertionCredentials 

key_location = '/home/selecaotwo/Dropbox/Public/my.ENV/' + os.sep + 'sys.CREDENTIALS' 
key_file_h = 'test-project-auth-a4f3c4bd20c4.json' 
print key_location + os.sep + key_file_h 

json_key = json.load(open(key_location + os.sep + key_file_h)) 
scope = ['https://spreadsheets.google.com/feeds'] 

credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope) 
gc = gspread.authorize(credentials) 

运行这段代码给我下面的错误:

/home/selecaotwo/Dropbox/Public/my.ENV//sys.CREDENTIALS/test-project-auth-a4f3c4bd20c4.json 
Traceback (most recent call last): 
    File "/home/selecaotwo/Desktop/gspread-test/gspread-test-001-codeRegist-0001.py", line 17, in <module> 
    gc = gspread.authorize(credentials) 
    File "/usr/local/lib/python2.7/site-packages/gspread/client.py", line 335, in authorize 
    client.login() 
    File "/usr/local/lib/python2.7/site-packages/gspread/client.py", line 98, in login 
    self.auth.refresh(http) 
    File "build/bdist.linux-x86_64/egg/oauth2client/client.py", line 598, in refresh 
    File "build/bdist.linux-x86_64/egg/oauth2client/client.py", line 769, in _refresh 
    File "build/bdist.linux-x86_64/egg/oauth2client/client.py", line 795, in _do_refresh_request 
    File "build/bdist.linux-x86_64/egg/oauth2client/client.py", line 1425, in _generate_refresh_request_body 
    File "build/bdist.linux-x86_64/egg/oauth2client/client.py", line 1554, in _generate_assertion 
    File "build/bdist.linux-x86_64/egg/oauth2client/crypt.py", line 162, in from_string 
    File "/usr/local/lib/python2.7/site-packages/OpenSSL/__init__.py", line 36, in <module> 
    from OpenSSL import crypto 
ImportError: /usr/local/lib/python2.7/site-packages/OpenSSL/crypto.so: undefined symbol: PyUnicodeUCS2_Decode 
[Finished in 0.1s with exit code 1] 
[shell_cmd: python -u "/home/selecaotwo/Desktop/gspread-test/gspread-test-001-codeRegist-0001.py"] 
[dir: /home/selecaotwo/Desktop/gspread-test] 
[path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] 

我读了论坛,这很可能是我的Ubuntu系统(14.04 LTS)和Python之间的问题( 2.7.9),但奇怪的是当我用--enable-encoding = usc2重新编译python时,我在同一行上得到了相同的错误,而不是说“未定义的符号:PyUnicodeUCS2_Decode”,它只是说“未定义的符号:PyUnicodeUCS4_Decode” 。这导致我相信这个问题可能是其他问题,我不知道如何继续。

我不确定这是否能解决问题。 而不是放入json文件本身,你可以尝试输入这样的client_email和私钥。 可以像这样复制client_email。对于私钥,代之以做:

key = u"-----BEGIN PRIVATE KEY-----\nBLABLA_\n-----END PRIVATE KEY-----\n".encode("utf-8") 


credentials = SignedJwtAssertionCredentials(client_email,key,scope) 
+0

雅各布,是的,这是我最终做的,它为我工作。感谢您的解决方案! – ColinKennedy