2016-12-16 66 views
2

下面是代码“类型错误:不能实例未知大小的CTYPE 'EVP_MD_CTX'” 而试图建立谷歌Prediction API进行

import httplib2, argparse, os, sys, json 
from oauth2client import tools, file, client 
from oauth2client.service_account import ServiceAccountCredentials 
from googleapiclient import discovery 
from googleapiclient.errors import HttpError 

scope = ['https://www.googleapis.com/auth/prediction','https://www.googleapis.com/auth/devstorage.read_only'] 

def get_api(api, scope, service_account=True): 
    storage = file.Storage('oAuth2.json') 
    creds = storage.get() 

    if creds is None or creds.invalid: 
     creds = ServiceAccountCredentials.from_json_keyfile_name('service_account.json', 
                  scopes=scope) 
     storage.put(creds) 

    http = creds.authorize(httplib2.Http()) 
    return discovery.build(api, 'v1.6', http=http) 

api = get_prediction_api('prediction') 

下面是在此基础上blog

错误

TypeError: cannot instantiate ctype 'EVP_MD_CTX' of unknown size

使用此功能google-api-python-client

回答

1

google-ap我安装的i-python-client(上面的链接)只适用于python2。截至今天,它不适用于conda env中的python2,仅在conda env之外,并且不适用于python 3.5。

+0

你有参考吗? [github页面](https://github.com/google/google-api-python-client)表示它与Python 3.4完全兼容,并且'此库可能适用于更高版本的3,但我们目前不运行测试反对这些版本。“我只是感到惊讶,它会在3.4而不是3.5 – User

+0

嗯我有类似的经验,这个错误确实消失了,当我尝试Python 2.7 – User

+0

其实我现在在Anaconda Python 3.5.2 。不幸的是,我没有确切的步骤,但我相信它是'pip install pyopenssl'并确保设置了'GOOGLE_APPLICATION_CREDENTIALS' – User

2

我发现这篇文章oauth2client有关的问题,在我的情况下,问题已解决更新到最新版本的pyOpenSSL,16.2.0在写作时。

+0

应该早一点问过,但你使用了哪个python版本?你有没有使用conda venv或python venv? – wi3o

-1

我没有积极点,但Chemary的答案为我工作。我正在使用python 3.5。我遇到了同样的问题,并且在安装pyOpenSSL时已经解决了。

pip install --upgrade pyOpenSSL