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

Azure Cognitive Services报错‘Resource Not Found’,请求排查原因

Troubleshooting 'Resource Not Found' Error with Azure Web Search API Script

That "Resource Not Found" error is almost always tied to issues with how you've configured your subscription key and endpoint in the script. Let's break down the most likely causes and fixes step by step:

Common Causes & Fixes

1. You didn't replace the placeholder values correctly

It sounds obvious, but it's the most frequent culprit. Double-check these lines in your code:

  • subscription_key = "YOUR_SUBSCRIPTION_KEY": Make sure you've replaced the entire string inside the quotes with one of the valid keys from your Azure Cognitive Services resource (you can find these in the "Keys and Endpoint" section of your resource in the Azure Portal). Don't leave the placeholder text there!
  • base_url = "YOUR_ENDPOINT": Same here—replace this with the full endpoint URL from the same "Keys and Endpoint" page. It should look something like https://your-resource-name.cognitiveservices.azure.com/ (don't forget the trailing slash).

2. You're using the wrong type of Cognitive Services resource

Web Search requires either a dedicated Web Search resource or a general Cognitive Services resource that has Web Search enabled. If you created a different resource type (like Computer Vision or Text Analytics), its key/endpoint won't work for Web Search. Head back to the Azure Portal and confirm your resource is configured for Web Search.

3. Your endpoint URL is malformed

Even a tiny typo here will break things:

  • Ensure the URL is complete (no missing parts like the region or resource name)
  • Avoid extra spaces before/after the URL when pasting it into your code
  • Make sure you're using the correct regional endpoint that matches where you deployed your resource (e.g., if your resource is in East US, your endpoint should reflect that)

4. Subscription key has extra characters or typos

Copy-pasting keys from the Azure Portal can sometimes sneak in extra spaces or invisible characters. Add a quick print statement to verify:

print("Subscription Key:", subscription_key)
print("Endpoint:", client.base_url)

Compare these outputs directly to the values in the Azure Portal—if there's any mismatch, fix it immediately.

5. Your resource hasn't finished deploying

New Azure resources can take a minute or two to fully provision. If you just created the resource, wait 5-10 minutes and try running the script again.

Example Corrected Code

Here's what your code should look like once you've plugged in your actual values:

# Import required modules.
from azure.cognitiveservices.search.websearch import WebSearchAPI
from azure.cognitiveservices.search.websearch.models import SafeSearch
from msrest.authentication import CognitiveServicesCredentials

# Replace with your actual subscription key from Azure Portal
subscription_key = "a1b2c3d4-5678-90ef-ghij-klmnopqrstuv"
# Replace with your actual endpoint URL
client = WebSearchAPI(CognitiveServicesCredentials(subscription_key), base_url = "https://my-web-search-resource.cognitiveservices.azure.com/")

# Make a request. Replace Yosemite if you'd like.
web_data = client.web.search(query="Yosemite")
print("\r\nSearched for Query# \" Yosemite \"")

If you're still stuck, check the Activity Log for your Azure resource—it might show more details about why the request is failing. You can also test your key/endpoint directly using a tool like Postman to rule out issues with the Python SDK.

内容的提问来源于stack exchange,提问作者Alvaro

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:40:20