Hi Airbyte! I'm trying to build a custom connector...
# replication-troubleshooting
a
Hi Airbyte! I'm trying to build a custom connector with Python CDK, and I'm having some issues at the "check_connection" step. I've tried to emulate the OneSignal source connector implementation, as specified in the tutorial
Copy code
def 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 :
Copy code
{"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
Copy code
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!
m
you can run the commands with the flag
--debug
which gives you more information about the request made
a
it gives me the exact same logs, but with
{"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 headers
m
using the debug flag it should print the logs of the headers and auth used
a
it doesn't 😕
m
Are you adding the token with a hardcoded string variable or are you trying to read from the condfig?
a
I'm doing this
Copy code
@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"],
        }
m
Can you confirm the error isn’t happening during the
get_authenticator
function? Are you able to print the token value?
a
yes, I'm able to print the token value, and it's showing, and it works
Copy code
print(stream.auth.token)
does show it, in my code above
n
Hi, @Alexandre Chouraki! Our team does not have the capacity to provide connector development coaching at this time. I would advise looking through connectors in the codebase and looking through the forum for former questions. I am closing this thread for the Community Assistance Team, but I also hope some community members chime in! Thanks for understanding 🙂
😢 1