For my python connector, I have this class. I want...
# help-connector-development
a
For my python connector, I have this class. I want to create a new class
ListMembers
which gets the
list_id
from the Lists class to use it in the url
lists/{list_id}/members
Copy code
class Lists(IncrementalMailChimpStream):
    cursor_field = "date_created"
    data_field = "lists"

    def path(self, **kwargs) -> str:
        return "lists"
k
A message from kapa.ai
To create a new class
ListMembers
that gets the
list_id
from the
Lists
class, you can follow a similar approach as shown in the [previous support conversation](https://airbytehq.slack.com/archives/C021JANJ6TY/p1657131854374819) from the Slack extracts. Here's how you can do it: 1. Create a new class
ListMembers
that inherits from
IncrementalMailChimpStream
or any other appropriate base class. 2. Override the
read_records
method in the
ListMembers
class to iterate through the records from the
Lists
class and get the
list_id
. 3. Use the
list_id
in the
path
method to construct the URL for the
ListMembers
API endpoint. Here's an example based on the information from the extracts:
Copy code
python class ListMembers(IncrementalMailChimpStream):     # Add any necessary fields and methods for the ListMembers class      def read_records(self, sync_mode: SyncMode, cursor_field: List[str] = None, stream_slice: Mapping[str, Any] = None, stream_state: Mapping[str, Any] = None) -> Iterable[Mapping[str, Any]]:         lists_stream = Lists(**kwargs)         for list_record in lists_stream.read_records(sync_mode=SyncMode.full_refresh):             list_id = list_record["id"]             yield from super().read_records(sync_mode=SyncMode.full_refresh, stream_slice={"list_id": list_id})      def path(self, stream_state: Mapping[str, Any] = None, stream_slice: Mapping[str, Any] = None, next_page_token: Mapping[str, Any] = None) -> str:         list_id = stream_slice["list_id"]         return f"lists/{list_id}/members"
This example assumes that you have a working
Lists
class and an appropriate base class for
ListMembers
. Make sure to adjust the code according to your specific implementation and requirements.
a
@kapa.ai i get the following error when i enter the code you provided
Copy code
{
  "type": "TRACE",
  "trace": {
    "type": "ERROR",
    "emitted_at": 1686869028212.925,
    "error": {
      "message": "Something went wrong in the connector. See the logs for more details.",
      "internal_message": "name 'kwargs' is not defined",
      "stack_trace": "Traceback (most recent call last):\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/main.py\", line 13, in <module>\n    launch(source, sys.argv[1:])\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/entrypoint.py\", line 156, in launch\n    for message in source_entrypoint.run(parsed_args):\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/entrypoint.py\", line 98, in run\n    yield from map(AirbyteEntrypoint.airbyte_message_to_string, self.read(source_spec, config, config_catalog, state))\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/entrypoint.py\", line 132, in read\n    yield from self.source.read(self.logger, config, catalog, state)\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py\", line 139, in read\n    raise e\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py\", line 120, in read\n    yield from self._read_stream(\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py\", line 194, in _read_stream\n    for record in record_iterator:\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/.venv/lib/python3.10/site-packages/airbyte_cdk/sources/abstract_source.py\", line 324, in _read_full_refresh\n    for record_data_or_message in record_data_or_messages:\n  File \"/workspaces/airbyte/airbyte-integrations/connectors/source-mailchimp/source_mailchimp/streams.py\", line 145, in read_records\n    lists_stream = Lists(**kwargs)\nNameError: name 'kwargs' is not defined\n",
      "failure_type": "system_error"
    }
  }
}
k
A message from kapa.ai
Hmm, I don't know enough to give you a confident answer yet. The error you provided is not directly related to the information extracts I have. I recommend checking the Airbyte [documentation](https://docs.airbyte.com) and [tutorials](https://airbyte.io/tutorials) for more information on how to resolve this issue.
a
@kapa.ai the error I provided tells me that
Copy code
lists_stream = Lists(**kwargs)\nNameError: name 'kwargs' is not defined"}}
k
A message from kapa.ai
Sorry @Aazam Thakur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support folks and they will try to fix me up! 🧑‍💻 Perhaps try again in 5mins?
a
@kapa.ai the error I provided tells me that
Copy code
lists_stream = Lists(**kwargs)\nNameError: name 'kwargs' is not defined"}}
k
A message from kapa.ai
Sorry @Aazam Thakur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support folks and they will try to fix me up! 🧑‍💻 Perhaps try again in 5mins?
a
@kapa.ai the error I provided tells me that
Copy code
lists_stream = Lists(**kwargs)\nNameError: name 'kwargs' is not defined"}}
k
A message from kapa.ai
Sorry @Aazam Thakur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support folks and they will try to fix me up! 🧑‍💻 Perhaps try again in 5mins?
a
@kapa.ai the error I provided tells me that lists_stream = Lists(**kwargs)\nNameError: name 'kwargs' is not defined"}}
k
A message from kapa.ai
Sorry @Aazam Thakur, I seem to be having a bit of trouble. Don't worry though, I've pinged my support folks and they will try to fix me up! 🧑‍💻 Perhaps try again in 5mins?