I am using PyDrive to create a Google Sheets file on a Google Shared Drive, the below code snippet successfully creates the file in my shared drive folder:
f = gd.CreateFile(
{'title': name, 'mimeType': 'application/vnd.google-apps.spreadsheet', 'parents': [{'teamDriveId': '1234', 'id': '1234'}]})
f.Upload(param={'supportsTeamDrives': True})
On adding the file, I am also trying to set permissions for an email address to gain write access to the file as below:
f.InsertPermission({'type': 'user', 'value': 'myemail#email.com', 'role': 'writer'})
On attempting to add the permissions, I receive the below error:
<HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/file_id_here/permissions?alt=json returned "File not found: file_id_here">
I have checked and the file id appears to be the same as the one that has been created.
I assumed that it wouldn't be any authorisation issue if I am able to create the file? Any suggestions would be very much appreciated.
Thanks
I have found it appears to be an issue with no entry for 'supportsTeamDrives' in the PyDrive's files.py file in the InsertPermission function.
I added the 'supportsTeamDrives' parameter into the code at line 325 as follows and it now appears to work:
permission = self.auth.service.permissions().insert(
fileId=file_id, body=new_permission, supportsTeamDrives=True).execute(http=self.http)
The best way I found using pyDrive was doing this:
file = gd.CreateFile({'title': 'filename', 'parents': [{'teamDriveId': '<your teamDriveId>', 'id': '<file id>'}]})
file.Upload(param={'supportsTeamDrives': True})
# here we can use the pydrive object to update.
new_permission = {
'id': 'anyoneWithLink',
'type': 'anyone',
'value': 'anyoneWithLink',
'withLink': True,
'role': 'reader'
}
permission = file.auth.service.permissions().insert(
fileId=file['id'], body=new_permission, supportsTeamDrives=True).execute(http=file.http)
Related
So, I have been struggling with a problem in the last couple of days for which I could really use come guidance.
Short version, I am trying to create a AVRO Reader Controller service in NiFi, using the nipyapi library.
Now, based on the documentation, we have:
nipyapi.canvas.create_controller(parent_pg, controller, name=None)
parent_pg = Target Parent PG
controller = Type of Controller to create, found via the list_all_controller_types method
name = Name for the new Controller as a String (Optional)
First of all I have tried to retrieve the list of all controller types and the following is the output for the controller I am trying to create:
{'bundle': {'artifact': 'nifi-record-serialization-services-nar',
'group': 'org.apache.nifi',
'version': '1.15.3'},
'controller_service_apis': [{'bundle': {'artifact': 'nifi-standard-services-api-nar',
'group': 'org.apache.nifi',
'version': '1.15.3'},
'type': 'org.apache.nifi.serialization.RecordReaderFactory'}],
'deprecation_reason': None,
'description': 'Parses Avro data and returns each Avro record as an separate '
'Record object. The Avro data may contain the schema itself, '
'or the schema can be externalized and accessed by one of the '
"methods offered by the 'Schema Access Strategy' property.",
'explicit_restrictions': None,
'restricted': False,
'tags': ['comma',
'reader',
'record',
'values',
'delimited',
'separated',
'parse',
'row',
'avro'],
'type': 'org.apache.nifi.avro.AvroReader',
'usage_restriction': None}
With this information, based on the documentation, I have tried to create this controller service:
root_id = canvas.get_root_pg_id() # retrieve the parent process group where I want to create the controller service
nipyapi.canvas.create_controller(root_id, 'org.apache.nifi.avro.AvroReader' , name="[TEST][PROJECT1] AVRO Reader - Table 1")
Unfortunately, I keep on getting an AssertionError within the create_controller function for "assert isinstance(controller, nipyapi.nifi.DocumentedTypeDTO) at line 1087"
Has anyone else encountered a similar issue?
And if so, how did you manage to fix it?
Or am I calling the create_controller function with invalid parameters?
Thank you.
Hello I am trying to export a csv file in a specific folder, I have tried several things and have no results
By doing the following code it exports me normally in the default /app/ folder
public function export(){
$super = Super::select('ano_plantacion','zona','sitio', 'manejo','sup_ha','codigo','rpend')->get();
Excel::store(new SuperExport($super), 'Super.csv'));
}
Im try with this:
Excel::store(new SuperExport($super), 'Super.csv', storage_path('/app/export'));
Error:
"Trying to access array offset on value of type null"
And this:
Excel::store(new SuperExport($super), storage_path('/app/export/Super.csv'));
Error:
Impossible to create the root directory "C:\Users\pachi\Documents\Version_web\mpe_web\storage\app\C:/Users/pachi/Documents/Version_web/mpe_web/storage/app/export
Help pls
Since the Excel store() method uses the default disk if you don't specify another one, which by default in laravel points to storage_path('app'), you can just prepend the export/ directory to the file name:
Excel::store( new SuperExport($super), '/export/Super.csv' );
Alternatively you can create a disk for the exports by adding the following array under the 'disks' index in the /config/filesystems.php file:
'disks' => [
// your other disks here, leave them as they are, and add this one
'export' => [
'driver' => 'local',
'root' => storage_path('app/export'),
],
],
And then you specify that disk as the third parameter to the store() method:
Excel::store( new SuperExport($super), 'Super.csv', 'export' );
I'm unable to a folder by providing an id to that folder using Boxr gem. Previously I didn't has the enterprise settings as shown in this post which I have now fixed. I'm creating a token using JWT authentication get_user_token method the following way.
token = Boxr::get_user_token("38521XXXX", private_key: ENV.fetch('JWT_PRIVATE_KEY'), private_key_password: ENV.fetch('JWT_PRIVATE_KEY_PASSWORD'), public_key_id: ENV.fetch('JWT_PUBLIC_KEY_ID'), client_id: ENV.fetch('BOX_CLIENT_ID'), client_secret: ENV.fetch('BOX_CLIENT_SECRET'))
I then pass this this token when creating a client.
client = Boxr::Client.new(token)
when I check the current user on client this is what I get:
client.current_user
=> {"type"=>"user",
"id"=>"60853XXXX",
"name"=>"OnlineAppsPoC",
"login"=>"AutomationUser_629741_06JgxiPtPj#boxdevedition.com",
"created_at"=>"2018-10-04T08:41:32-07:00",
"modified_at"=>"2018-10-04T08:41:50-07:00",
"language"=>"en",
"timezone"=>"America/Los_Angeles",
"space_amount"=>10737418240,
"space_used"=>0,
"max_upload_size"=>2147483648,
"status"=>"active",
"job_title"=>"",
"phone"=>"",
"address"=>"",
"avatar_url"=>"https://app.box.com/api/avatar/large/6085300897"}
When I run client.methods I see there is folder_from_id however when I call that method I get the following error:
pry(#<FormsController>)> client.folder_from_id("123456", fields: [])
Boxr::BoxrError: 404: Not Found
from /usr/local/bundle/gems/boxr-1.4.0/lib/boxr/client.rb:239:in `check_response_status'
I have the following settings:
I also authorize the application. Not sure what else to do.
token = Boxr::get_user_token(user_id,
private_key: ENV.fetch('JWT_PRIVATE_KEY'),
private_key_password: ENV.fetch('JWT_PRIVATE_KEY_PASSWORD'),
public_key_id: ENV.fetch('JWT_PUBLIC_KEY_ID'),
client_id: ENV.fetch('BOX_CLIENT_ID'),
client_secret: ENV.fetch('BOX_CLIENT_SECRET'))
client = Boxr::Client.new(token.access_token)
folder = client.folder_from_id(folder_id)
client.upload_file(file_path, folder)
For anybody using C# and BOXJWT.
You just need to have a boxManager set up and will get you with anything you need, say BoxFile, Folder etc.
If you have the folderID, well & good, but if you need to retrieve, this can be done as shown below:
string inputFolderId = _boxManager.GetFolder(RootFolderID).Folders.Where(i => i.Name == boxFolder).FirstOrDefault().Id; //Retrieves FolderId
Folder inputFolder = _boxManager.GetFolder(inputFolderId);
I'm getting the following error when trying to create a hold using the Google Vault API:
HttpError 500 when requesting
https://vault.googleapis.com/v1/matters/{matterId}/holds?alt=json
returned "Internal error encountered."
from google.oauth2 import service_account
import googleapiclient.discovery
SCOPES = ['https://www.googleapis.com/auth/ediscovery']
SERVICE_ACCOUNT_FILE = './serviceaccount.json'
credentials = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
delegated_credentials = credentials.with_subject('delegateuser#example.com')
client = googleapiclient.discovery.build('vault', 'v1', credentials=delegated_credentials)
data = { 'name': 'test', 'accounts': [{'email': 'testuser#example.com' }], 'corpus': 'MAIL', 'query': { 'mailQuery': {'terms': 'to:ceo#company.com'} }}
results = client.matters().holds().create(matterId='{matterId}', body=data).execute()
I've replaced the actual matterId string with {matterId}.
Creating matters, listing matters and listing holds work just fine.
I've tried different combinations of fields to include in the request body but the docs are not clear as to which are required...
It turns out you can't use 'email' in holds().create() - you must use accountId, or the 'id' number for the gmail user.
You can use emails to create holds
https://developers.google.com/vault/guides/holds#create_a_hold_for_mail_on_specific_user_accounts_with_a_search_query
I'm almost done with a multipart file upload but not quite. The API I am using requires two parts: a meta description (Json) and a file (File).
Here some of the Code:
File.open(file_path) do |image|
request = Net::HTTP::Post::Multipart.new(
url.path,
'metadata' => metadata_as_json_string,
'attachment' => UploadIO.new(image, "image/jpeg", "image.jpg")
)
The trouble I am having is with the 'metadata' part (metadata_as_json_string). Without it everything works fine, but the API requires meta information as json. It works if I save the json content in a file and use it as metadata-part. But my content is not coming from a file.
Any ideas how to provide the metadata without previously saving it in a file?
Thank you
I did find a solution myself by using StringIO:
metadata_file = StringIO.new(metadata_as_json_string)
File.open(file_path) do |image|
request = Net::HTTP::Post::Multipart.new(
url.path,
'metadata' => UploadIO.new(metadata_file, "application/json"),
'attachment' => UploadIO.new(image, "image/jpeg", "image.jpg")
)
Anyway thank you for your time