Why do I get credential read in error on google slide API? - google-api

I downloaded the gsuite developers python code from :
(https://github.com/gsuitedevs/python-samples)
I then enabled api access and downloaded the credentials.json file and ran the quickstart.py in:
(python-samples-master/slides/quickstart) and it worked and outputted
The presentation contains 5 slides:
- Slide #1 contains 4 elements.
- Slide #2 contains 11 elements.
- Slide #3 contains 9 elements.
- Slide #4 contains 5 elements.
- Slide #5 contains 12 elements.
So it worked. Then I tried to run test_snippets.py in:
(python-samples-master/slides/snippets)
And I get an error
======================================================================
ERROR: setUpClass (__main__.SnippetsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1228, in _implicit_credentials_from_files
credentials_filename)
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1397, in _get_application_default_credential_from_file
AUTHORIZED_USER + "' or '" + SERVICE_ACCOUNT + "' values)")
oauth2client.client.ApplicationDefaultCredentialsError: 'type' field should be defined (and have one of the 'authorized_user' or 'service_account' values)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_snippets.py", line 32, in setUpClass
super(SnippetsTest, cls).setUpClass()
File "~/Desktop/python-samples-master/slides/snippets/base_test.py", line 27, in setUpClass
cls.credentials = cls.create_credentials()
File "~/Desktop/python-samples-master/slides/snippets/base_test.py", line 44, in create_credentials
credentials = GoogleCredentials.get_application_default()
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1271, in get_application_default
return GoogleCredentials._get_implicit_credentials()
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1256, in _get_implicit_credentials
credentials = checker()
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1231, in _implicit_credentials_from_files
extra_help, error)
File "~/anaconda3/lib/python3.7/site-packages/oauth2client/client.py", line 1429, in _raise_exception_for_reading_json
credential_file + extra_help + ': ' + str(error))
oauth2client.client.ApplicationDefaultCredentialsError: An error was encountered while reading json file: ~/Documents/credentials/credentials.json (pointed to by GOOGLE_APPLICATION_CREDENTIALS environment variable): 'type' field should be defined (and have one of the 'authorized_user' or 'service_account' values)
I definitely have a GOOGLE_APPLICATION_CREDENTIALS that points to the same credentials that successfully ran quickstart.py.
Is there something else I need or do I need to change some code to load the credentials data in?
It seems like GoogleCredentials.get_application_default() call is the one that is erroring
def create_credentials(cls):
credentials = GoogleCredentials.get_application_default()
scope = [
'https://www.googleapis.com/auth/drive',
]
return credentials.create_scoped(scope)

The file pointed to the environment variable GOOGLE_APPLICATION_CREDENTIALS is not a valid service account json file.
Open your service account json file. The beginning of the file should look similar to this:
{
"type": "service_account",
"project_id": "development-123456",
"private_key_id": "19c38bac6560abcdef01234567ac4da7991cbaad",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANB

Related

ADSError 857212673: Can't read variable values through name (pyads)

I've been having a problem lately where I can't access the value of any variable through their name. It's not a connection problem since I can read the value from the read() function just fine. However whenever I use the read_by_name function there's always the same error pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).
Because it's an unknown error I haven't been able to find documentation on it. I'm using a BC9120 as a PLC and TwinCat 2. Does anyone know what might be causing this?
Code:
if self.plc.is_open == False:
self.plc.open()
print(self.plc.read(pyads.INDEXGROUP_MEMORYBIT, 0*8 + 0, pyads.PLCTYPE_BOOL))
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
Logs:
False
Traceback (most recent call last):
File "c:\Users\MAP9AV\Documents\Banca\Modelo Preditivo\Thread_Sup.py", line 50, in run
print(self.plc.read_by_name("Test.M0", pyads.PLCTYPE_BOOL))
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\connection.py", line 540, in read_by_name
return adsSyncReadByNameEx(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 1154, in adsSyncReadByNameEx
handle = adsGetHandle(port, address, data_name)
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 890, in adsGetHandle
handle = adsSyncReadWriteReqEx2(
File "C:\Users\MAP9AV\AppData\Local\Programs\Python\Python39\lib\site-packages\pyads\pyads_ex.py", line 774, in adsSyncReadWriteReqEx2
raise ADSError(err_code)
pyads.pyads_ex.ADSError: ADSError: Unknown Error (857212673).

DataprocCreateClusterOperator fails due to TypeError

EDIT 1: The problem is related to the field "initialization_actions". Originally I'd put a String there, now I gave it the object it's asking for:
from google.cloud.dataproc_v1beta2 import NodeInitializationAction
CLUSTER_CONFIG = {
...
"initialization_actions": NodeInitializationAction({
"executable_file": <string>})]
}
Unfortunately it's still complaining:
ERROR - Parameter to MergeFrom() must be instance of same class: expected google.cloud.dataproc.v1beta2.NodeInitializationAction got NodeInitializationAction.
I am trying to deploy a Dataproc cluster with airflow.providers.google.cloud.operators.dataproc.DataprocCreateClusterOperator, but I get a cryptic TypeError.
Here is the task definition:
CLUSTER_CONFIG = {
"config_bucket": <my_bucket>,
"temp_bucket": <my_bucket>,
"master_config": {
"num_instances": 1,
"machine_type_uri": "c2-standard-8",
"disk_config": {"boot_disk_type": "pd-standard", "boot_disk_size_gb": 1024},
},
"initialization_actions": [<string>],
}
create_cluster = DataprocCreateClusterOperator(
task_id="create_cluster",
project_id=PROJECT_ID,
cluster_config=CLUSTER_CONFIG,
region=REGION,
cluster_name=CLUSTER_NAME,
metadata=[("ENV", ENV)],
dag=dag)
Traceback:
Traceback (most recent call last)
File "/usr/local/lib/airflow/airflow/models/taskinstance.py", line 985, in _run_raw_tas
result = task_copy.execute(context=context
File "/usr/local/lib/airflow/airflow/providers/google/cloud/operators/dataproc.py", line 603, in execut
cluster = self._create_cluster(hook
File "/usr/local/lib/airflow/airflow/providers/google/cloud/operators/dataproc.py", line 540, in _create_cluste
metadata=self.metadata
File "/usr/local/lib/airflow/airflow/providers/google/common/hooks/base_google.py", line 425, in inner_wrappe
return func(self, *args, **kwargs
File "/usr/local/lib/airflow/airflow/providers/google/cloud/hooks/dataproc.py", line 304, in create_cluste
metadata=metadata
File "/opt/python3.6/lib/python3.6/site-packages/google/cloud/dataproc_v1beta2/services/cluster_controller/client.py", line 412, in create_cluste
request = clusters.CreateClusterRequest(request
File "/opt/python3.6/lib/python3.6/site-packages/proto/message.py", line 506, in __init_
pb_value = marshal.to_proto(pb_type, value
File "/opt/python3.6/lib/python3.6/site-packages/proto/marshal/marshal.py", line 208, in to_prot
pb_value = rule.to_proto(value
File "/opt/python3.6/lib/python3.6/site-packages/proto/marshal/rules/message.py", line 32, in to_prot
return self._descriptor(**value
TypeError: Parameter to MergeFrom() must be instance of same class: expected google.cloud.dataproc.v1beta2.NodeInitializationAction got str
The field `initialization_actions" is not a list of strings, but a list of dicts:
"initialization_actions": [{"executable_file": <string>}]

azure-sdk-python status code not found GraphRbacManagementClient

I am trying to enumerate Azure AD users from an azure subscription, with this code:
WORKING_DIRECTORY = os.getcwd()
TENANT_ID = "REDACTED_AZURE_ID_OF_MY_AZURE_AD_USER"
AZURE_AUTH_LOCATION = os.path.join(WORKING_DIRECTORY, "mycredentials.json") # from: az ad sp create-for-rbac --sdk-auth > mycredentials.json
# I've tried with get_client_from_cli_profile() while logged in azure CLI
# I've tried with and without parameters auth_path and tenant_id
rbac_client = get_client_from_auth_file(GraphRbacManagementClient,auth_path=AZURE_AUTH_LOCATION, tenant_id=TENANT_ID)
# Try to list users
for user in rbac_client.users.list():
pprint(user.__dict__)
As I've detailed in the comments, I've tried to fix the issue with a couple of unsuccessful attempts, here is the stacktrace
/home/guillaumedsde/.virtualenvs/champollion/bin/python /home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py
Traceback (most recent call last):
File "/home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py", line 582, in <module>
gitlab_project_member.access_level)
File "/home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py", line 306, in create_role_assignment
"principal_id": get_user_azure_id(user)} # get_user_azure_id(user)} # TODO
File "/home/guillaumedsde/PycharmProjects/champollion/champollion/champollion.py", line 329, in get_user_azure_id
for user in rbac_client.users.list():
File "/home/guillaumedsde/.virtualenvs/champollion/lib/python3.6/site-packages/msrest/paging.py", line 131, in __next__
self.advance_page()
File "/home/guillaumedsde/.virtualenvs/champollion/lib/python3.6/site-packages/msrest/paging.py", line 117, in advance_page
self._response = self._get_next(self.next_link)
File "/home/guillaumedsde/.virtualenvs/champollion/lib/python3.6/site-packages/azure/graphrbac/operations/users_operations.py", line 158, in internal_paging
raise models.GraphErrorException(self._deserialize, response)
azure.graphrbac.models.graph_error.GraphErrorException: Operation returned an invalid status code 'Not Found'
Process finished with exit code 1
Was a bug fixed in azure-common 1.1.13
https://pypi.org/project/azure-common/1.1.13/
You can now simply do that (with no tenant ID)
rbac_client = get_client_from_auth_file(GraphRbacManagementClient,auth_path=AZURE_AUTH_LOCATION)
I took this opportunity to fix the CLI version of this method as well.
(I own this code at MS)

how do I set a turtle to an image

I am trying to set my image to a file, but when i run it i get
Exception in Tkinter callback Traceback (most recent call last):
File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 1699, in call
return self.func(*args) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 686, in eventfun
fun() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py",
line 20, in up
combat() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py",
line 57, in combat
enemy.shape(image) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 2777, in shape
self.turtle._setshape(name) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 2506, in _setshape
self._item = screen._createimage(screen._shapes["blank"]._data) File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 723, in _createimage
return self.cv.create_image(0, 0, image=image) File "", line 1, in create_image File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 2483, in create_image
return self._create('image', args, kw) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 2474, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage1" doesn't exist
when I have the file name clearly stated exactly where it is on my pc.
the code
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")
turtle = Turtle()
turtle.setimage("Crawfish_attack.gif")
thanks in advance
BTW the link is here
and the rest of the code all works and is not needed to be shown
Remove "\\Crawfish_attack" from the os.chdir() arguments. You need to path to the folder it is in, not the file. That is what the register_shape function will do is pull the exact file in that folder.
You were getting the error because you were trying to path to something (it was looking for a folder) that does not exist.
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")

Remove cell from table

I have created my own Sales / Quotation report caleed sale_order.sxw using OpenOffice Write. From there I generate the sale_order.rml file.
I have two installation of OpenERP, one on Windows and one on Ubuntu.
In OOWriter, I have a 4 columns table that prints out each single order line along with Quantity, "Print this" text and Subtotal.
The third column is printed out only if a specific condition is met, based on the price list name containing "final":
So I expect:
If "final" is not located within the price list
Product A|2|Print this |20
If "final" is located within the price list:
Product A|2|20
To solve this, I have the following code:
(so.partner_id.property_product_pricelist.name.find('final') > 0) and "Print this" or removeParentNode('td')
It works fine from the windows installation.
But when I run the same file from the Ubuntu installation I get an AssertionError message and I can't print out my Sales / Quotation pdf report.
I did some testing specifically with the removeParentNode('td') and the error seems to come from there, but I can't work out why as it works under windows!
Here is the log from the Ubuntu server:
2013-04-15 13:09:07,822 1621 ERROR ? openerp.service.web_services: Exception:
Traceback (most recent call last):
File "/home/download/openerp-6.1-20121008-233119/openerp/service/web_services.py", line 727, in go
(result, format) = obj.create(cr, uid, ids, datas, context)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/report_sxw.py", line 442, in create
fnct_ret = fnct(cr, uid, ids, data, report_xml, context)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/report_sxw.py", line 511, in create_source_pdf
return self.create_single_pdf(cr, uid, ids, data, report_xml, context)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/report_sxw.py", line 533, in create_single_pdf
pdf = create_doc(etree.tostring(processed_rml),rml_parser.localcontext,logo,title.encode('utf8'))
File "/home/download/openerp-6.1-20121008-233119/openerp/report/interface.py", line 207, in create_pdf
obj.render()
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/render.py", line 59, in render
self._result = self._render()
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml.py", line 41, in _render
return rml2pdf.parseNode(self.rml, self.localcontext, images=self.bin_datas, path=self.path,title=self.title)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 1007, in parseNode
r.render(fp)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 314, in render
pt_obj.render(el)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 983, in render
fis += r.render(node_story)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 877, in render
return process_story(node_story)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 870, in process_story
flow = self._flowable(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 834, in _flowable
return self.render(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 877, in render
return process_story(node_story)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 870, in process_story
flow = self._flowable(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 793, in _flowable
return self._table(node)
File "/home/download/openerp-6.1-20121008-233119/openerp/report/render/rml2pdf/trml2pdf.py", line 697, in _table
assert length == len(node.get('colWidths').split(','))
AssertionError
2013-04-15 13:09:07,951 1621 ERROR ? openerp.netsvc:
(<type 'exceptions.AssertionError'>, AssertionError(), <traceback object at 0x7ff558e54b00>)
2013-04-15 13:09:07,953 1621 INFO ? werkzeug: 192.168.2.4 - - [15/Apr/2013 13:09:07] "POST /web/report HTTP/1.1" 500 -
I did a comparison between the trml2pdf.py files used on the server and the one used by windows and they are identical.
This is because of un matching original column.

Resources