2016-12-16 65 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