You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python版Microsoft Bot Framework运行示例报错:405方法不允许

Fixing 405: Method Not Allowed When Running Bot Builder Python Samples

Hey there, let’s break down why you’re hitting that 405 error and walk through how to get your bot up and running properly!

First, Why the 405 Error?

This is actually a common gotcha: Bot Framework samples are built to accept only POST requests (since they’re designed to receive messages from chat platforms or the Bot Emulator). When you type http://localhost:9000 into a browser, you’re sending a GET request—something the bot’s endpoint isn’t configured to handle. That’s why you see the 405 response.


Do You Need to Modify Code or Create a Bot Service?

Let’s tackle both questions:

1. Bot Service Keys (App ID/Password)

Most basic samples (like the Echo Bot) don’t require an Azure Bot Service key to run locally. The only time you need these credentials is if you’re using cloud features like LUIS, QnA Maker, or connecting your bot to channels like Teams/WhatsApp.

If your sample has a config.py or .env file with fields for MICROSOFT_APP_ID and MICROSOFT_APP_PASSWORD, you can leave them blank or comment them out for local testing—no need to create an Azure Bot Service yet.

2. Testing the Bot Correctly

You can’t test a bot directly in a browser. Instead, use the Bot Framework Emulator:

  • Install the emulator (it’s free and made for this exact purpose).
  • When you open the emulator, enter your bot’s endpoint—this is almost always http://localhost:9000/api/messages (note the /api/messages path; most samples don’t expose the root URL for bot traffic).
  • If you didn’t set up app credentials, just click "Connect"—you’ll be able to chat with your bot right away.

If You Still Run Into Issues

Double-check these code details:

  • Open your main app file (usually app.py) and verify the route configuration. For Flask-based samples, it should look like this:
    @app.route("/api/messages", methods=["POST"])
    def messages():
        # Bot logic here
    
    Make sure methods=["POST"] is explicitly set—if it’s missing or includes GET, you’ll get 405 errors.
  • Confirm the port number in your console output matches the one you’re trying to access (some samples use port 3978 instead of 9000 by default).

内容的提问来源于stack exchange,提问作者Alejandro Peña

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:05:10