2016-10-20 1 views
12

전 도메인 위임과 함께 G Suite 서비스 계정을 사용하고 있습니다. Google 캘린더에 읽기 전용으로 액세스 할 수있는 스크립트가 있습니다. 스크립트는 제대로 작동하지만 서비스를 "빌드"할 때 오류가 발생합니다 (백그라운드 스레드에서?).Google 서비스 계정에 Python 클라이언트를 사용할 때 "ImportError : file_cache를 사용할 수 없음"file_cache

WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using oauth2client >= 4.0.0 
Traceback (most recent call last): 
    File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/__init__.py", line 36, in autodetect 
    from google.appengine.api import memcache 
ImportError: No module named 'google' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module> 
    from oauth2client.contrib.locked_file import LockedFile 
ImportError: No module named 'oauth2client.contrib.locked_file' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/file_cache.py", line 37, in <module> 
    from oauth2client.locked_file import LockedFile 
ImportError: No module named 'oauth2client.locked_file' 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/__init__.py", line 41, in autodetect 
    from . import file_cache 
    File "/Users/myuseraccount/anaconda3/lib/python3.5/site-packages/googleapiclient/discovery_cache/file_cache.py", line 41, in <module> 
    'file_cache is unavailable when using oauth2client >= 4.0.0') 
ImportError: file_cache is unavailable when using oauth2client >= 4.0.0 

여기 무슨 일이야 내가 고칠 수있는이 일이 :

from oauth2client.service_account import ServiceAccountCredentials 
from httplib2 import Http 
import urllib 
import requests 
from apiclient.discovery import build 

cal_id = "[email protected]" 

scopes    = ['https://www.googleapis.com/auth/calendar.readonly'] 
credentials   = ServiceAccountCredentials.from_json_keyfile_name('my_cal_key.json', scopes=scopes) 
delegated_credentials = credentials.create_delegated('[email protected]') 
http_auth    = delegated_credentials.authorize(Http()) 

# This is the line that throws the error 
cal_service = build('calendar','v3',http=http_auth) 

#Then everything continues to work normally 
request = cal_service.events().list(calendarId=cal_id) 
response = request.execute() 

# etc... 

오류 발생합니다 : 여기 코드는? 나는 google 패키지를 재설치 및/또는 업그레이드하려고 시도했습니다.

+0

이 업데이트는 무엇입니까? 나는 또한 지금 막 동일한 문제점을 만났다 –

답변

10

모듈의 코드 헤드는 "구글-API - 파이썬 클라이언트"라고

install_requires = [ 
    'httplib2>=0.9.2,<1dev', 
    'oauth2client>=1.5.0,<5.0.0dev', <<============= 
    'six>=1.6.1,<2dev', 
    'uritemplate>=3.0.0,<4dev', 
] 

그래서 oauth2client 버전 4.0.0을 제거했습니다.

그런 다음 oauth2cli를 다운로드했습니다. 나는이 다운로드 한 파일을 설치 한 https://pypi.python.org/pypi/oauth2client/1.5.2

offial 파이썬 사이트에서 tar.gz 파일에서 엔트 1.5.2 그래서 난 그 후

Package     Version 
------------------------ --------- 
certifi     2016.9.26 
discovery    0.0.4 
distribute    0.7.3 
future     0.16.0 
google-api-python-client 1.5.5 
httplib2     0.9.2 
oauth2client    1.5.2 
pefile     2016.3.28 
pip      9.0.1 
pyasn1     0.1.9 
pyasn1-modules   0.0.8 
PyInstaller    3.2 
pypiwin32    219 
requests     2.11.1 
rsa      3.4.2 
setuptools    28.8.0 
six      1.10.0 
uritemplate    3.0.0 

는, ALL 다시 확인하고있다 oauth2client의 1.5.2 버전을 가지고 경고 메시지가 없습니다.

+0

지정된 요구 사항을 감안할 때 모듈에 대한 버그입니다. 그럼, 맞지? – Clay

+4

Ftr : v4.0.0을 제거한 후 이전 버전을 pip :'$ pip install oauth2client == 3.0.0'을 통해 직접 설치할 수 있습니다. Cf [releases] (https://github.com/google/oauth2client/releases). – dtk

+1

패키지 제거 명령을 모르는 사람들을위한이 명령 :'pip uninstall oauth2client' –

0

Python 클라이언트 용 Google API를 사용하려면 먼저 Google API가 Python 모듈에 내장되어 있지 않으므로 먼저 설치해야합니다. 지침은 Install the Library에 있습니다.

설치

당신은 패키지 관리자를 사용하거나 다운로드하여 수동으로 Python 클라이언트 라이브러리를 설치할 수 있습니다 :

관리 설치

사용 핍 또는 설치를 관리 할 수 ​​setuptools에을 (당신이해야 할 수도 있습니다 sudo를 먼저 실행하십시오.) :

pip (선호) :

$ pip install --upgrade google-api-python-client

setuptools에 다음 easy_install을 도구는 setuptools에 패키지에 포함 된 사용 ...

$ easy_install --upgrade google-api-python-client

+0

고마워, 그러나 나는 이미 그것을했다. 내가 말했듯이, 스크립트는 정상적으로 작동합니다. 배경 스레드에서 오류를 발생시키는 것을 유발하는 것은 오직 한 줄입니다. – Clay

+0

이것이 [이 모듈에없는 locked_file # 414] (https://github.com/google/oauth2client/issues/414)에 언급 된 것이 었는지 확인하십시오. [oauth2client v2.0.0과의 비 호환성 수정] # 182] (https://github.com/google/google-api-python-client/pull/182). – noogui

+1

솔직히 말해서 나는 말할 수 없다. 나는 GitHub 페이지의 지시 사항을 사용하여 pip와 함께 설치했다 :'pip install --upgrade google-api-python-client', 그래서 패키지의 1.5.4 버젼을 가지고있다. contrib 서브 모듈이 있지만, 패키지 디렉토리의 어느 곳에서나'locked_file' 서브 모듈을 볼 수 없습니다. – Clay

-5

이 오류는 credentials.json 파일에 대한 권한이 충분하지 않아 표시되었습니다.

credentials.json은 Google 자격 정보 파일입니다. 시스템의 이름은 다를 수 있습니다.

그냥 chmod를 777 ~/credentials.json을 할

코딩 해피!

+0

자격 증명 파일의 경우 모드를 777로 변경하는 것은 나쁜 습관이라고 생각합니다. – tector

12

비트 늦게 여기에 파티에 있지만 오늘은 비슷한 문제가 있었에만 오류 here

솔루션 답을 발견 file_cache is unavailable when using oauth2client >= 4.0.0

솔루션 :

변경하여 discovery.build() 분야를 가지고 cache_discovery=False

discover.build(api, version, http=http, cache_discovery=False) 
+2

이것은 매우 쉬운 수정이며 라이브러리 다운 그레이드를 포함하지 않습니다. +1 – raphael

+2

이것을 했습니까? 감사! – madtyn

관련 문제