I'm trying to access a google app through the Python Client using this code to gain authorization (private info obviously redacted):
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import SignedJwtAssertionCredentials
from oauth2client.tools import run
f = open('privatekey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
service_account_name='name#developer.gserviceaccount.com',
private_key=key,
scope = 'https://www.googleapis.com/auth/calendar')
http = httplib2.Http()
http = credentials.authorize(http)
service = build(serviceName='calendar', version='v3', http=http)
Yet I receive this error:
ImportError: cannot import name SignedJwtAssertionCredentials
I have installed the Google v3 API Python Client as well as OAuth2; I don't seem to be having any other problems with those modules, though I haven't used them much. Anyone know what's going on?
I had this problem today and had to roll back from oauth2client version 2.0 to version 1.5.2 with:
pip install oauth2client==1.5.2
It seems like you havn't installed pyopenssl. Install via easy_install pyopenssl.
Libraries oauth2client.client
if HAS_OPENSSL:
# PyOpenSSL is not a prerequisite for oauth2client, so if it is missing then
# don't create the SignedJwtAssertionCredentials or the verify_id_token()
# method.
class SignedJwtAssertionCredentials(AssertionCredentials):
....
The source repository was recently updated, to make use of the new code:
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
...
As alexander margraf said you need PyOpenSSL to import SignedJwtAssertionCredentials
simply: pip install pyopenssl
REMEMBER: It will fail on Windows if you don't have OpenSSL Win32 libs installed http://slproweb.com/products/Win32OpenSSL.html (you need full package, not the light version). Also keep in mind you need to add it to your path var before installing pyopenssl
I was trying to build a local dev environment and none of the solutions here were working. The extra piece in the puzzle for me was:
$ pip install pycrypto
possibly in addition to any or all of:
$ pip install pyopenssl
$ pip install httplib2
$ pip install oauth2client
$ pip install ssl
GAE has the pycrypto package available internally (check the libraries listed in your app.yaml) so something needing it might work on their machines but not yours - I think - sorry I'm not yet clear on what and why they're making life so miserable with the libraries yet.
Check your oauth2client version first.
If this version >= 2.0, using the ServiceAccountCredentials instead of SignedJwtAssertionCredentials.
Look at the three reference:
Issue:
https://github.com/google/oauth2client/issues/401
Upgrade to 2.0
https://github.com/google/oauth2client/releases/tag/v2.0.0
Docs
http://oauth2client.readthedocs.io/en/latest/source/oauth2client.service_account.html#module-oauth2client.service_account
You can try this for oauth2client version >= 2.0,
from oauth2client.service_account import ServiceAccountCredentials
ServiceAccountCredentials.from_p12_keyfile(
service_account_email='name#developer.gserviceaccount.com',
filename=KEY_PATH,
scopes='https://www.googleapis.com/auth/calendar')
Check your `oauth2client' module version, probably you are using greater then 1.5.2 version if that is so, you can fix this problem by downgrading the version and reinstalling the 1.5.2 or 'oauth2client.client.AccessTokenCredentials'. Documentation link https://oauth2client.readthedocs.io/en/latest/source/oauth2client.client.html
Related
I am installing google cloud datastore to build a conversational chatbot, using the command
!pip install google-cloud-datastore
This gives me following error:
google-cloud-bigquery 1.9.0 has requirement google-cloud-core<0.30dev,>=0.29.0, but you'll have google-cloud-core 1.4.3 which is incompatible.
goes on to installing google-cloud-core-1.4.3 google-cloud-datastore-1.15.3.
Execute further
from google.cloud import datastore
gives following error:
/usr/local/envs/py3env/lib/python3.5/site-packages/google/cloud/_http.py in ()
20 import warnings
21
---> 22 from six.moves import collections_abc
23 from six.moves.urllib.parse import urlencode
ImportError: cannot import name 'collections_abc'
Package google-cloud-bigquery=1.9.0 seems to be old, I have google-cloud-bigquery=1.28.0. You can try to update first your Cloud SDK components and then install google-cloud-datastore again. You can update the components with:
gcloud components update
It is possible that you will be required to execute equivalent apt-get update command.
The second error with collections_abc seems to be a compatibility issue, python2 is being deprecated, please use Python3 (pip3). If the issue with six persists, try installing different version for instance; pip3 install six==1.15.0 as recommended in this github thread.
Using the Gmail API in Python 3.7 to retrieve emails and I'm testing the code in both Terminal and Pycharm, yet I cannot get past line 7:
#!/usr/bin/env python3
import pickle
import os.path
import email
import base64
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
I recieve the error message:
from googleapiclient.discovery import build
ModuleNotFoundError: No module named 'googleapiclient'
I understand there have been other similar questions regarding this same issue but none of the answers appear to help in this situation.
Please see below for things I have tried and information which may help illicit a solution.
1) It appears that the packages are present and accounted for in the expected folders.
user/PycharmProjects/projectname/venv/lib/python3.7/site-packages
__pycache__
apiclient
cachetools
cachetools-4.1.0.dist-info
dateutil
easy-install.pth
easy_install.py
google
google_api_python_client_py3-1.2-py3.7.egg-info
google_auth-1.14.2-py3.8-nspkg.pth
google_auth-1.14.2.dist-info
google_auth_httplib2-0.0.3.dist-info
google_auth_httplib2.py
httplib2
httplib2-0.17.3.dist-info
numpy
numpy-1.18.4.dist-info
oauth2client
pandas
pandas-1.0.3.dist-info
pip-10.0.1-py3.7.egg
pkg_resources
pyasn1
pyasn1-0.4.8.dist-info
pyasn1_modules
pyasn1_modules-0.2.8.dist-info
python_dateutil-2.8.1.dist-info
pytz
pytz-2020.1.dist-info
rsa
rsa-4.0.dist-info
setuptools
setuptools-46.1.3.dist-info
setuptools.pth
six-1.14.0.dist-info
six.py
uritemplate
2) The project interpreters also appear to be correct:
3) Have tried reinstalling the module via PyCharm > Preferences
4) I have tried various pip commands including the following;
pip install google-api-python-client
pip install googleapiclient
pip install --upgrade google-api-python-client
Just don't understand what the issue is or how to resolve so your guidance and suggestions would be greatly appreciated.
You dont have 'google-api-python-client'. You instead have 'google-api-python-client-py3'. The former has to be available in the list of libraries:
I have installed it with:
pip install google-api-python-client
Also check if you are running the code with the same interpreter in which you installed google-api-python-client.
I wanted to deploy my app engine to use machine learning engine in Gcloud with the following code:
https://github.com/novinfard/temp
I encountered a strange error as follows:
ImportError: No module named oauth2client.client
However this library have already installed in app engine, as the following upgrade command return that everything is updated:
sudo pip install --upgrade google-api-python-client
I applied the 'vendor' solutions as described here as well:
https://stackoverflow.com/a/44011777/3477974
But this does not work either.
How this problem can be solved?
As of version 1.7.0 of google-api-python-client the hard requirement for oauth2client has been dropped. I.e. it will not be included when installing the google-api-python-client.
You can fix this by manually installing oauth2client in your vendor folder.
$ pip install -t <vendor_folder> oauth2client
This release drops the hard requirement on oauth2client and installs
google-auth by default instead. oauth2client is still supported but will
need to be explicitly installed.
https://github.com/google/google-api-python-client/releases/tag/v1.7.0
Any idea what package I am missing.
Python:
#!/usr/bin/env python
import requests
import requests_cache
Error:
/bin/requests_cache/backends/init.py", line 54, in create_backend
_backend_dependencies[backend_name])
ImportError: You must install the python package: sqlite3
I have included the packages certfil, chardet, idna, requests, requests_cache and urllib3 in the execute directory..
I have it working on a python deployment with the following:
pip list
Package Version
-------------- ---------
certifi 2018.4.16
chardet 3.0.4
idna 2.6
pip 10.0.1
pysqlite 2.7.0
requests 2.18.4
requests-cache 0.4.13
urllib3 1.22
I know it says sqlite3 which I have tried including locally but this does not work.
sqlite3 is part of the standard library, but there are some environments where it isn't supported, for example cloud providers that use ephemeral storage. One that I'm aware of is Heroku: https://devcenter.heroku.com/articles/sqlite3
If that's the case for your environment, consider using one of the other backends instead: https://requests-cache.readthedocs.io/en/stable/user_guide/backends.html
Current versions of requests-cache will fall back to a non-persistent in-memory cache if sqlite3 isn't available.
I've just created a Google Cloud compute engine, installed google-cloud package with both pip and pip3, and I'm experiencing the following error when launching a script with python3
from google.cloud import bigquery
File "/usr/local/lib/python3.5/dist-packages/google/cloud/bigquery/__init__.py", line 35,
in <module>
from google.cloud.bigquery.client import Client
File "/usr/local/lib/python3.5/dist-packages/google/cloud/bigquery/client.py", line 36, in
<module>
(more traceback lines..)
from pyasn1_modules.rfc2459 import Certificate
File "/usr/local/lib/python3.5/dist-packages/pyasn1_modules/rfc2459.py", line 20, in <modu
le>
from pyasn1.type import opentype
ImportError: cannot import name 'opentype'
On the compute engine the following packages are installed:
pyasn1==0.1.9
pyasn1-modules==0.2.1
google-cloud==0.30.0
google-cloud-bigquery==0.28.0
Which can be the problem here?
Posting my solution in case it helps someone else - this fixed it for me:
pip install --upgrade google-auth-oauthlib
More details discussed here: https://www.raspberrypi.org/forums/viewtopic.php?f=114&t=198933&p=1241439#p1241439
It looks like you have an issue with pyasn1, so you could try installing a newer version (the latest is 0.4.2), or even reinstalling it manually with:
sudo apt-get --reinstall install python-pyasn1 python-pyasn1-modules
And if you are inside a virtualenv, use instead:
pip install pyasn1 pyasn1-modules
FWIW - Had the same issue - none of the above worked. I eventually discovered that if I did it under sudo it did work.
stracing the original - I found that I had a ~/.local directory which had a pyasn1 directory where it was trying to get the files from, but the opentype.py one did not appear there. When I deleted that whole directory - it started working.
I assume it was some sort of cache that was partial, and out-of-date???