iwatkot / py3xui

Sync and Async Object-oriented Python SDK for the 3x-ui API.
MIT License
26 stars 3 forks source link

Client Update Occurs Error #9

Closed Flashbaurger888888 closed 4 weeks ago

Flashbaurger888888 commented 2 months ago

Hi, i want to update my client with this api but it occurs error:

raise ValueError(f"Response status is not successful, message: {message}")
ValueError: Response status is not successful, message: Something went wrong! Failed: empty client ID

I've tried 2.3.9, 2.3.10 and 2.3.11 before but no one couldn't help me, also the client update example did not work either.

iwatkot commented 2 months ago

@Flashbaurger888888, hello!

Thanks for reaching out. From the error output, it looks like the incorrect client UUID was provided. There are some strange features in the 3x-ui API behavior: E.g. when getting the client from API you'll receive a numerical client ID (e.g. 1, 2, 3), but when updating the client you need to provide its UUID.

Here's code reference for updating a client to set a traffic limit:

async def some_other_function():
    user_uuid = str(uuid.uuid4())
    new_client = Client(id=user_uuid, email=str(telegram_id), enable=True)

    await api.client.add(inbound.id, [new_client])

    await set_traffic_limit(telegram_id, user_uuid)

async def set_traffic_limit(telegram_id: int, user_uuid: str) -> None:
    client = await api.client.get_by_email(str(telegram_id))
    client.id = user_uuid
    client.total_gb = gigabytes_to_bytes(Settings().traffic_limit)
    await api.client.update(user_uuid, client)

Pay attention to the line client.id = user_uuid. Could you please confirm that the correct client UUID was set before making an API call?

Thank you Sincerely

iwatkot commented 2 months ago

Here's a screenshot from the panel for reference:

image

iwatkot commented 2 months ago

@Flashbaurger888888 I've also added a new FAQ section to discussions, it also includes your case, I believe. https://github.com/iwatkot/py3xui/discussions

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 4 weeks ago

This issue was closed because it has been inactive for 7 days since being marked as stale.