【发布时间】:2015-05-14 06:36:16
【问题描述】:
我无法运行代码来读取 Tastekid 的 API (python),它显示错误:403(禁止请求)但是我可以访问与浏览器中的 url 相同的内容。 钥匙也试过了。
请在查询下方找到
from urllib2 import Request, urlopen, URLError
req = Request('http://www.tastekid.com/api/similar?q=red+hot+chili+peppers%2C+pulp+fiction')
try:
response = urlopen(req)
except URLError as e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
elif hasattr(e, 'code'):
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
else:
'everything is fine'
【问题讨论】: