Skip to content

找不到本地部署的bot #318

@1Fleeting-time

Description

@1Fleeting-time

我在下面附上了我的代码和报错信息。我的bot id和api_coze_token已经删除,但是 我确认过是正确的
我的报错信息:
python coze__test.py
[cozepy][WARNING][2025-09-15 15:46:21] request POST#https://api.coze.cn/v3/chat failed, logid=2025091515462100FB6E72D0F6FD79B56A, code=4200, msg=Requested resource bot_id=XXXdoes not exist. Ensure you are the correct resource identifier.
Traceback (most recent call last):
File "/home/jingkuchen/桌面/coze__test.py", line 18, in
chat = coze.chat.create(
File "/home/jingkuchen/conda_envs/coze-env/lib/python3.10/site-packages/cozepy/chat/init.py", line 467, in create
return self._create(
File "/home/jingkuchen/conda_envs/coze-env/lib/python3.10/site-packages/cozepy/chat/init.py", line 659, in _create
return self._requester.request(
File "/home/jingkuchen/conda_envs/coze-env/lib/python3.10/site-packages/cozepy/request.py", line 271, in request
return self.send(request)
File "/home/jingkuchen/conda_envs/coze-env/lib/python3.10/site-packages/cozepy/request.py", line 388, in send
return self._parse_response(
File "/home/jingkuchen/conda_envs/coze-env/lib/python3.10/site-packages/cozepy/request.py", line 448, in _parse_response
raise CozeAPIError(code, msg, logid, debug_url)
cozepy.exception.CozeAPIError: code: 4200, msg: Requested resource bot_id=XXXdoes not exist. Ensure you are the correct resource identifier., logid:
我的代码:
import os # noqa
import time

Get an access_token through personal access token oroauth.

api_coze_token = ""

os.getenv("COZE_API_TOKEN")

from cozepy import Coze, TokenAuth, Message, ChatStatus, MessageContentType, ChatEventType # noqa
from cozepy import COZE_CN_BASE_URL

Init the Coze client through the access_token.

coze = Coze(auth=TokenAuth(token=api_coze_token), base_url=COZE_CN_BASE_URL)

Create a bot instance in Coze, copy the last number from the web link as the bot's ID.

bot_id = ""

The user id identifies the identity of a user. Developers can use a custom business ID

or a random string.

user_id = "1111"

chat = coze.chat.create(
bot_id=bot_id,
user_id=user_id,
additional_messages=[
Message.build_user_question_text("生成财务报表")
],
)

# Assume the development allows at most one chat to run for 10 minutes. If it exceeds 10
# minutes, the chat will be cancelled.
# And when the chat status is not completed, poll the status of the chat once every second.
# After the chat is completed, retrieve all messages in the chat.

start = int(time.time())
timeout = 600
while chat.status == ChatStatus.IN_PROGRESS:
if int(time.time()) - start > timeout:
# too long, cancel chat
coze.chat.cancel(conversation_id=chat.conversation_id, chat_id=chat.id)
break

time.sleep(1)
# Fetch the latest data through the retrieve interface
chat = coze.chat.retrieve(conversation_id=chat.conversation_id, chat_id=chat.id)

When the chat status becomes completed, all messages under this chat can be retrieved through the list messages interface.

messages = coze.chat.messages.list(conversation_id=chat.conversation_id, chat_id=chat.id)
for message in messages:
print(f"role={message.role}, content={message.content}")`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions