I'm trying to sync between python and google drive with the following details:
Authorized JavaScript origins: http://localhost:8080
Authorized redirect URIs: http://localhost:8080/
I copied the json file to the directory and ran this code:
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
and I got this error:
from oauth2client.locked_file import LockedFile
ImportError: No module named locked_file
Can you please help me?
Had the same issue.
It looks there was a change in the newest version of the oauth2client, v2.0.0, which broke compatibility with the google-api-python-client module, which now got fixed https://github.com/adrian-the-git/google-api-python-client/commit/2122d3c9b1aece94b64f6b85c6707a42cca8b093, so an upgrade of the google-api-python-client restores compatibility and make everything working again:
$ pip install --upgrade git+https://github.com/google/google-api-python-client
Related
I have a Zip file named 'mathoverflow.net.7z' in my google drive which I have loaded to colab using the given code. But, when I try to unzip it I get an error. Please suggest a way to rectify this.
This is my code:
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
downloaded = drive.CreateFile({'id':'15h0f8p9n6OG1B796q-gbP5oXstCuOcDM'})
downloaded.GetContentFile('mathoverflow.net.7z')
Till this it works fine. But when I run this I get the following error.
!unzip mathoverflow.net.7z
Archive: mathoverflow.net.7z End-of-central-directory signature not
found. Either this file is not a zipfile, or it constitutes one
disk of a multi-part archive. In the latter case the central
directory and zipfile comment will be found on the last disk(s) of
this archive. unzip: cannot find zipfile directory in one of
mathoverflow.net.7z or
mathoverflow.net.7z.zip, and cannot find mathoverflow.net.7z.ZIP, period.
You can use 7z instead. It's already pre-installed in Colab
!7z e mathoverflow.net.7z
!pip install pyunpack
!pip install patool
from pyunpack import Archive
Archive('file_name.7z').extractall('path/to/')
unzip will not work, you need a different tool: https://www.simplified.guide/linux/extract-7z-file
I don't know that you have installation privileges on colab, so you might have to do it in the privacy of your own machine.
I need to work with API via wsdl and I'm trying to figure out how zeep module works. The module was installed with "pip install" and it shows the same error every time.
ImportError: cannot import name 'Client' from 'zeep'
from zeep import Client
client = Client('http://www.webservicex.net/ConvertSpeed.asmx?WSDL')
result = client.service.ConvertSpeed(
100, 'kilometersPerhour', 'milesPerhour')
assert result == 62.137 ```
First of all, do a pip freeze and make sure that zeep is installed.
If it's installed then make sure your source file is not named zeep.py or it will not work.
[edit]
From someone else on Github: "And ensure there's no zeep.pyc in the folder"
This leads me to believe that there should be no source file with the name zeep in the folder.
Link to GitHub discussion
You need to set permissions on the zeep library.
Set permissions on the library directory in the site-packages directory.
chmod -R 777 zeep
I'm new to Google Cloud Platform, and have uploaded some machine learning code on Jupyter notebook in DataLab.
My issue is although, I installed Google Cloud Storage (using the command: pip install --upgrade google-cloud-storage), I'm unable to import this.
The following is how I'm importing this package:
>>import numpy
>>import pandas as pd
>>from google.cloud import storage
But I'm getting the following error:
ImportErrorTraceback (most recent call last)
in ()
----> 1 from google.cloud import storage
ImportError: cannot import name storage
Note:
This is the content of my JSON config file: {"TokenSources":["env"]}
I tried export GOOGLE_APPLICATION_CREDENTIALS="/path/to/file.json", but the error persists.
I verified that this package is indeed installed in my environment by typing pip freeze in the command shell:
google-cloud==0.34.0
google-cloud-datastore==1.7.0
google-cloud-spanner==1.4.0
google-cloud-storage==1.10.0
What am I missing here?
Have you installed the google-cloud-storage package in your DataLab environment, or on your local machine? You'll need to run the following command within DataLab:
!pip install google-cloud-storage
See https://cloud.google.com/datalab/docs/how-to/adding-libraries for more details
Also, the google-cloud package is deprecated, you shouldn't need to install it, see https://pypi.org/project/google-cloud/.
So I got it working upon importing storage as follows:
import google.datalab.storage as storage
To make your notebooks resilient to both datalab and non-datalab environments you can use one of the the following methods for handling your import statements:
try:
from google.cloud import storage
except ImportError:
from google.datalab import storage
or
if 'google.datalab' in sys.modules:
from google.datalab import storage
else:
from google.cloud import storage
Alternatively if you would like to switch datalab to using from google.cloud import storage
Run the following in a cell
!pip install google-cloud-storage
Followed by this cell to reset the IPython kernel
# Reset the IPython kernel
from IPython.core.display import HTML
HTML("<script>Jupyter.notebook.kernel.restart()</script>")
Note: You need to reset the Python kernel after installation otherwise you will a ContextualVersionConflict error from naming conflicts
I am trying to utilize the Google Cloud Platform's Stack Driver API with the following Python/Flask code below...
view.py
import google.cloud
from google.cloud import monitoring_v3
# from google.cloud.monitoring_v3 import query
requirements.txt
Flask==0.12.2
oauth2client==2.0.1
google-api-python-client==1.6.2
facebookads==2.11.1
httplib2==0.10.3
enum==0.4.6
requests-toolbelt==0.8.0
google-cloud-storage==1.6.0
google-resumable-media==0.3.1
google-auth
google-cloud-monitoring==0.28.0
google-cloud
For whatever reason it can't seem to find the monitoring_v3 library as when whenever I run the code I am getting the following error...
from google.cloud import monitoring_v3
ImportError: cannot import name monitoring_v3
I have tried to update to google-cloud-monitoring==0.29.0 and that just churns out another non-related error.
I solved it by upgrading monitoring 0.29.0 to 1.1.0
pip install --upgrade google-cloud-monitoring
Latest version now available is 2.0.0
https://pypi.org/project/google-cloud-monitoring/
Could be a conflict (dependency or otherwise) between google-api-python-client and google-cloud*.
The former is a REST client which includes the monitoring API, the latter is gRPC based client.
Are you using 'google-api-python-client' for anything else? If no, try removing that?
Make sure your requirements.txt file is proper, and located in the source directory where you have the main.py.
If everything fails , copy a requirements.txt file from a working function , and replace the requirements modules in it (strangely this worked for me :P)
When I do :
from oauth2client.client import SignedJwtAssertionCredentials
in my main.py which is served using the App Engine development server, I am getting an error :
ImportError: cannot import name SignedJwtAssertionCredentials
When I ran from a standard python console the same statement, I am not getting any error. The import works fine.
I confirm that I have pyopenssl installed on my system. I have already read this post which suggest only to install it: ImportError: cannot import name SignedJwtAssertionCredentials
Any idea of what's wrong with the development server?
PS : My main goal is to connect to BigQuery
Instead of using SignedJwtAssertionCredentials and deploying your PKCS12 key with your application, you can use AppAssertionCredentials from the oauth2client.appengine package. Ensure that your appengine application service is added to your project and you are good to go.
Looks like a long standing issue with the AppEngine environment: https://code.google.com/p/google-api-python-client/issues/detail?id=133