Laura Vaida
03/03/2021, 4:31 PMUnexpected error: TypeError("'NoneType' object is not subscriptable")
Zanie
None
that you are attempting to access like a list ie x = None; x[0]
Laura Vaida
03/03/2021, 4:32 PMgcs_result = GCSResult(bucket='billwerk')
@task
def oauth(username,password,client_id,client_secret):
oauth = OAuth2Session(client=LegacyApplicationClient(client_id=client_id))
token = oauth.fetch_token(
token_url="<https://app.billwerk.com/oauth/token>",
username=username,
password=password,
client_id=client_id,
client_secret=client_secret,
)
return token
@task
def creating_json(token):
bw_contracts_call = requests.get('<https://app.billwerk.com/api/v1/contracts?access_token=>' + token['access_token'])
return requests.get('<https://app.billwerk.com/api/v1/contracts?access_token=>' + token['access_token']).json()
@task(cache_for=datetime.timedelta(hours=1), result=gcs_result)
def last_entry(json):
# Getting last contract id for while loop
last_entry = json[199]['Id']
return last_entry
here the flowLaura Vaida
03/03/2021, 4:33 PMZanie
json
is None
or json[199]
is NoneLaura Vaida
03/03/2021, 4:35 PMwith Flow("billwerk-contracts") as flow:
username = PrefectSecret("BW_Username")
password = PrefectSecret("BW_Password")
client_id = PrefectSecret("BW_Client_Id")
client_secret = PrefectSecret("BW_Client_Secret")
token = oauth(username=username, password=password, client_id=client_id, client_secret=client_secret)
json = creating_json(token=token)
that's the flowLaura Vaida
03/03/2021, 4:35 PMZanie
json
object in the last_entry
task so you can inspect itLaura Vaida
03/03/2021, 4:37 PMZanie
Zanie
Laura Vaida
03/03/2021, 7:12 PMLaura Vaida
03/03/2021, 7:44 PMZanie
Laura Vaida
03/03/2021, 7:59 PMZanie
Laura Vaida
03/03/2021, 8:02 PM@task(log_stdout=True)
def creating_json(token):
bw_contracts_call = requests.get('<https://app.billwerk.com/api/v1/contracts?access_token=>' + token['access_token'])
print(requests.get('<https://app.billwerk.com/api/v1/contracts?access_token=>' + token['access_token']).json())
return requests.get('<https://app.billwerk.com/api/v1/contracts?access_token=>' + token['access_token']).json()
@task(cache_for=datetime.timedelta(hours=1), result=gcs_result, log_stdout=True)
def last_entry(json):
# Getting last contract id for while loop
last_entry = json[199]['Id']
return last_entry
Laura Vaida
03/03/2021, 8:02 PMLaura Vaida
03/03/2021, 8:02 PMflow.storage = Docker(registry_url="<http://gcr.io/keller-steering-enabling/flows|gcr.io/keller-steering-enabling/flows>", image_name="billwerk-contracts",
python_dependencies=["pandas", "oauthlib ", "requests", "requests_oauthlib", "datetime", "oauth2client", "snowflake"])
flow.run_config = KubernetesRun()
flow.register('Billwerk')
that the flow runLaura Vaida
03/03/2021, 8:02 PMZanie
Laura Vaida
03/03/2021, 8:08 PMwith Flow("billwerk-contracts") as flow:
username = PrefectSecret("BW_Username")
password = PrefectSecret("BW_Password")
client_id = PrefectSecret("BW_Client_Id")
client_secret = PrefectSecret("BW_Client_Secret")
token = oauth(username=username, password=password, client_id=client_id, client_secret=client_secret)
json = creating_json(token=token)
last_entry = last_entry(json)
Zanie
last_entry = last_entry(json)
which could cause problems.Laura Vaida
03/03/2021, 8:12 PMLaura Vaida
03/03/2021, 8:22 PMLaura Vaida
03/03/2021, 8:22 PMLaura Vaida
03/03/2021, 8:22 PMUnexpected error: Forbidden('POST <https://storage.googleapis.com/upload/storage/v1/b/billwerk/o?uploadType=multipart>: {\n "error": {\n "code": 403,\n "message": "Insufficient Permission",\n "errors": [\n {\n "message": "Insufficient Permission",\n "domain": "global",\n "reason": "insufficientPermissions"\n }\n ]\n }\n}\n: (\'Request failed with status code\', 403, \'Expected one of\', <HTTPStatus.OK: 200>)')
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2343, in upload_from_file
created_json = self._do_upload(
File "/usr/local/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2165, in _do_upload
response = self._do_multipart_upload(
File "/usr/local/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 1728, in _do_multipart_upload
response = upload.transmit(
File "/usr/local/lib/python3.8/site-packages/google/resumable_media/requests/upload.py", line 149, in transmit
self._process_response(response)
File "/usr/local/lib/python3.8/site-packages/google/resumable_media/_upload.py", line 116, in _process_response
_helpers.require_status_code(response, (http_client.OK,), self._get_status_code)
File "/usr/local/lib/python3.8/site-packages/google/resumable_media/_helpers.py", line 99, in require_status_code
raise common.InvalidResponse(
google.resumable_media.common.InvalidResponse: ('Request failed with status code', 403, 'Expected one of', <HTTPStatus.OK: 200>)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/prefect/engine/runner.py", line 48, in inner
new_state = method(self, state, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/prefect/engine/task_runner.py", line 898, in get_task_run_state
result = self.result.write(value, **formatting_kwargs)
File "/usr/local/lib/python3.8/site-packages/prefect/engine/results/gcs_result.py", line 77, in write
self.gcs_bucket.blob(new.location).upload_from_string(binary_data)
File "/usr/local/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2567, in upload_from_string
self.upload_from_file(
File "/usr/local/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 2359, in upload_from_file
_raise_from_invalid_response(exc)
File "/usr/local/lib/python3.8/site-packages/google/cloud/storage/blob.py", line 3886, in _raise_from_invalid_response
raise exceptions.from_http_status(response.status_code, message, response=response)
google.api_core.exceptions.Forbidden: 403 POST <https://storage.googleapis.com/upload/storage/v1/b/billwerk/o?uploadType=multipart>: {
"error": {
"code": 403,
"message": "Insufficient Permission",
"errors": [
{
"message": "Insufficient Permission",
"domain": "global",
"reason": "insufficientPermissions"
}
]
}
}
: ('Request failed with status code', 403, 'Expected one of', <HTTPStatus.OK: 200>)
Laura Vaida
03/03/2021, 8:23 PMZanie
result
type in the code you gave me but it looks like this is where the error is occuringLaura Vaida
03/03/2021, 8:26 PMLaura Vaida
03/03/2021, 8:26 PMfrom prefect.engine.results import GCSResult
gcs_result = GCSResult(bucket='billwerk')
Laura Vaida
03/03/2021, 8:26 PM@task(cache_for=datetime.timedelta(hours=1), result=gcs_result, log_stdout=True)
def defining_last_entry(json):
# Getting last contract id for while loop
last_entry = json[199]['Id']
return last_entry
Laura Vaida
03/03/2021, 8:26 PMZanie
Zanie
Laura Vaida
03/03/2021, 8:27 PMLaura Vaida
03/03/2021, 8:27 PMprefect.context.secrets.GCP_CREDENTIALS
for automatic authentication - see Third Party Authentication for more information.Zanie
GCSResult
per https://docs.prefect.io/orchestration/recipes/third_party_auth.html#declaring-secrets-on-storageLaura Vaida
03/03/2021, 8:28 PMZanie
Zanie
flow.add_task(PrefectSecret("GCP_CREDENTIALS"))
to your flow?Laura Vaida
03/03/2021, 8:34 PMZanie
Laura Vaida
03/03/2021, 8:35 PMwith Flow("billwerk-contracts") as flow:
username = PrefectSecret("BW_Username")
password = PrefectSecret("BW_Password")
client_id = PrefectSecret("BW_Client_Id")
client_secret = PrefectSecret("BW_Client_Secret")
token = oauth(username=username, password=password, client_id=client_id, client_secret=client_secret)
json = creating_json(token=token)
flow.add_task(PrefectSecret("GCP_CREDENTIALS"))
last_entry = defining_last_entry(json)
Laura Vaida
03/03/2021, 8:35 PMZanie
Laura Vaida
03/03/2021, 8:55 PMLaura Vaida
03/03/2021, 8:56 PMLaura Vaida
03/03/2021, 8:56 PMLaura Vaida
03/03/2021, 8:56 PMLaura Vaida
03/03/2021, 8:56 PMLaura Vaida
03/03/2021, 9:07 PMLaura Vaida
03/03/2021, 9:07 PMLaura Vaida
03/03/2021, 9:11 PMLaura Vaida
03/03/2021, 9:11 PMLaura Vaida
03/03/2021, 9:14 PM/opt/prefect/healthcheck.py:153: UserWarning: Task <Task: defining_last_entry> has cache settings but some upstream dependencies do not have result types. See <https://docs.prefect.io/core/concepts/results.html> for more details.
result_check(flows)
just getting this error in the flow registration partZanie
Laura Vaida
03/04/2021, 9:04 AMLaura Vaida
03/05/2021, 5:52 PMZanie
flow.run()
locally and printing your credentials then testing a file upload using them to make sure the credentials that the flow uses are indeed permissioned correctly.Zanie
Docker(... secrets=["GCP_CREDENTIALS"])
Zanie
Laura Vaida
03/05/2021, 6:24 PM