我编写了一个脚本来使用 Pybing 生成 url。
from pybing import Bing
bing = Bing('mykey')
response = bing.search_web('python bing')
print response['SearchResponse']['Web']['Total']
results = response['SearchResponse']['Web']['Results']
print len(results)
for result in results[:3]:
print repr(result['Title'])
我得到的错误是
Traceback (most recent call last):
File "C:\Python27\Project\YQL.py", line 4, in <module>
print response['SearchResponse']['Web']['Total']
KeyError: 'Web'
在打印响应变量时我得到
{u'SearchResponse': {u'Errors': [{u'HelpUrl': u'http://msdn.microsoft.com/en-
us/library/dd251042.aspx', u'Message': u'Parameter has invalid value.', u'Code': 1002,
u'Parameter': u'SearchRequest.AppId', u'Value': u'mykey'}], u'Query':
{u'SearchTerms': u'pyt'}, u'Version': u'2.0'}}
我应该如何修复代码。