How to use service account in google python api and disk?

I am trying to write a python 2.7 script to upload a file to my personal folder with google.

After a few problems, I know. This is my current error:

NotImplementedError: PKCS12 format is not supported by PyCrpto library. Try converting to "PEM" (openssl pkcs12 -in xxxxx.p12 -nodes -nocerts) privatekey.pem) or using PyOpenSSL if the source code is an option.

I have already tried running these commands as mentiod in this question and.

openssl pkcs12 -in privatekey.p12 -nodes -nocerts > privatekey.pem openssl pkcs8 -nocrypt -in privatekey.pem -passin pass:notasecret -topk8 -out pk.pem 

my privatekey.p12, downloaded from the new modern fancy Google developers console, was original with the name something-0123eed.json and looked like this: 1 :

 { "private_key_id": "9ced108fe72345373b75b03d7e967a3f8c0084ca", "private_key": "-----BEGIN PRIVATE KEY-----\nxe91Tr6RHs57LKX2HivFmOQwcFoJkUPrbB6Gwy8prE...Pc9jNExo5Krp1kLrkJYxAOmUWxWwPJ4pCx7Lxc6uQQnAlKyRmnfVpdS2I0\n-----END PRIVATE KEY-----\n", "client_email": " 0KsVeSAa91UtEGvY9lil@developer.gserviceaccount.com ", "client_id": "0KsVeSAa91UtEGvY9lil.apps.googleusercontent.com", "type": "service_account" } 

My python code is as follows:

 #!/bin/env python2.7 from apiclient.discovery import build from apiclient.http import MediaFileUpload import httplib2 from oauth2client.client import SignedJwtAssertionCredentials credentials = SignedJwtAssertionCredentials( service_account_name=' 0KsVeSAa91UtEGvY9lil@developer.gserviceaccount.com ', private_key=key, scope = [ 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/drive.appdata', 'https://www.googleapis.com/auth/drive.apps.readonly' ] ) http = httplib2.Http() http = credentials.authorize(http) drive_folder_id = 'jhIKHOG6supMhpjPJFHffZarwxP6' service = build('drive', 'v2', http=http) media_body = MediaFileUpload('/path/to/superfile.gpg'), mimetype='application/pgp-encrypted') body = { 'title': 'superfile.gpg', 'description': '', 'mimeType': 'application/pgp-encrypted', 'parents': [{'id': drive_folder_id}] } file = service.files().insert( body=body, media_body=media_body).execute() 

1: (of course, I changed the values ​​with garbage)

+1
python google-api pkcs # 12 pycrypto google-api-python-client
source share
1 answer

I found the answer in this question :

 openssl pkcs12 -passin pass:notasecret -in privatekey.p12 -nocerts -passout pass:notasecret -out key.pem openssl pkcs8 -nocrypt -in key.pem -passin pass:notasecret -topk8 -out privatekey.pem rm key.pem 

But before that I had to regenerate a new private key, but in P12 format.

generate new P12 key

+4
source share

All Articles