Laura Vaida
03/03/2021, 11:44 AMAmanda Wee
03/03/2021, 12:51 PMLaura Vaida
03/03/2021, 1:31 PMLaura Vaida
03/03/2021, 1:33 PM@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=PrefectResult)
def last_entry(json):
# Getting last contract id for while loop
return json[199]['Id']
with 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)
flow.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')
Laura Vaida
03/03/2021, 1:33 PMLaura Vaida
03/03/2021, 1:33 PMLaura Vaida
03/03/2021, 2:19 PMSean Talia
03/03/2021, 2:53 PMLaura Vaida
03/03/2021, 2:54 PMLaura Vaida
03/03/2021, 2:55 PMSean Talia
03/03/2021, 2:56 PMLaura Vaida
03/03/2021, 2:57 PMSean Talia
03/03/2021, 2:57 PM@task(cache_for=datetime.timedelta(hours=1), result=PrefectResult)
you need to do
@task(cache_for=datetime.timedelta(hours=1), result=PrefectResult())
Laura Vaida
03/03/2021, 2:58 PMSean Talia
03/03/2021, 2:58 PMLaura Vaida
03/03/2021, 2:59 PMSean Talia
03/03/2021, 2:59 PMLaura Vaida
03/03/2021, 2:59 PMSean Talia
03/03/2021, 3:00 PMLaura Vaida
03/03/2021, 3:01 PMLaura Vaida
03/03/2021, 3:02 PMLaura Vaida
03/03/2021, 3:03 PMSean Talia
03/03/2021, 3:06 PMLaura Vaida
03/03/2021, 3:06 PMSean Talia
03/03/2021, 3:10 PMSean Talia
03/03/2021, 3:11 PMRequest failed with status for 403 Expected one of...
Laura Vaida
03/03/2021, 3:11 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>)
Sean Talia
03/03/2021, 3:26 PMLaura Vaida
03/03/2021, 3:37 PMSean Talia
03/03/2021, 3:48 PMLaura Vaida
03/03/2021, 4:07 PM