Alexandre Chouraki
11/29/2022, 6:00 PMdef check_connection(self, logger, config) -> Tuple[bool, any]:
try:
args = self.convert_config2stream_args(config)
stream = ExportPatients(**args)
print(stream.auth.token)
records = stream.read_records(sync_mode=SyncMode.full_refresh)
next(records)
return True, None
except Exception as e:
return False, e
But when testing it, I get these logs :
{"type": "LOG", "log": {"level": "ERROR", "message": "[{\"errorCode\":\"TOKEN_NOT_FOUND\",\"componentType\":\"AUTH\",\"message\":\"JWT Token is not present in request headers\",\"details\":{},\"date\":\"2022-11-29T17:34:52.907Z\"}]"}}
{"type": "LOG", "log": {"level": "ERROR", "message": "Check failed"}}
{"type": "CONNECTION_STATUS", "connectionStatus": {"status": "FAILED", "message": "HTTPError('401 Client Error: for url: <https://api.live.welkincloud.io/{redacted}/{redacted}/export/PATIENT>')"}}
Even though I do have a token set up in stream.auth, it's printing well, and doing
tok = "the_token_that_was_printed"
h = {
"Authorization": "Bearer {}".format(tok)
}
r = requests.get(f"<https://api.live.welkincloud.io/{redacted}/{redacted}/export/PATIENT>", headers=h)
in Python yields a 200 instead of a 401...
I can't fathom why that won't work, if the token can be found... Is there a way to check the headers of a request from the stream object? I could definitely use some help!Marcos Marx (Airbyte)
11/29/2022, 6:20 PM--debug which gives you more information about the request madeAlexandre Chouraki
11/29/2022, 6:22 PM{"type": "DEBUG", "message": "Debug logs enabled", "data": {}} in the beginning... I know the url that was queried, and it's the right one, according to the error message that I get... what I need to check is most likely the headersMarcos Marx (Airbyte)
11/29/2022, 6:23 PMAlexandre Chouraki
11/29/2022, 6:25 PMMarcos Marx (Airbyte)
11/29/2022, 6:35 PMAlexandre Chouraki
11/29/2022, 6:43 PMAlexandre Chouraki
11/29/2022, 6:44 PM@classmethod
def get_authenticator(cls, config: Mapping[str, Any]) -> TokenAuthenticator:
tenant_name = config.get("tenant_name")
client_name = config.get("client_name")
client_secret = config.get("client_secret")
r = <http://requests.post|requests.post>(f"<https://api.live.welkincloud.io/{tenant_name}/admin/api_clients/{client_name}>", json={"secret":client_secret})
token = r.json()["token"]
return TokenAuthenticator(token=token)
@classmethod
def convert_config2stream_args(cls, config: Mapping[str, Any]) -> Mapping[str, Any]:
"""Convert input configs to parameters of the future streams
This function is used by unit tests too
"""
return {
"start_date": config["start_date"],
"authenticator": cls.get_authenticator(config),
"tenant_name": config["tenant_name"],
"instance_name": config["instance_name"],
}Marcos Marx (Airbyte)
11/29/2022, 6:45 PMget_authenticator function? Are you able to print the token value?Alexandre Chouraki
11/29/2022, 6:48 PMAlexandre Chouraki
11/29/2022, 6:48 PMprint(stream.auth.token)
does show it, in my code aboveNataly Merezhuk (Airbyte)
11/30/2022, 6:03 PM