下本地工作,但不是urllib2的錯誤時:AppEngine上
import urllib
import urllib2
import simplejson as json
url = 'https://www.googleapis.com/rpc'
requests = [{
'method': 'freebase.text.get',
'apiVersion': 'v1',
'params': {
'id': ['en','bob_dylan']
}
},{
'method': 'freebase.text.get',
'apiVersion': 'v1',
'params': {
'id': ['en','blade_runner']
}
}]
headers = { 'Content-Type': 'application/json' }
req = urllib2.Request(url, json.dumps(requests), headers)
response = urllib2.urlopen(req)
print response.read()
在部署時,它拋出以下錯誤:
class 'urllib2.HTTPError': HTTP Error 404: Not Found
Traceback (most recent call last):
File "/base/data/home/apps/s~34thquote/1.359254037177435492/test.py", line 38, in <module>
response = urllib2.urlopen(req)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 387, in open
response = meth(req, response)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/base/python_runtime/python_dist/lib/python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
這可能涉及到這個問題:freebase api error on deployment to appengine: DownloadError: ApplicationError: 2在這種情況下,在請求中添加api鍵可以修復它。雖然我嘗試添加一個鍵(使用網址抓取)導致錯誤:
{u'code': 100, u'message': u'Invalid API Key (Key not found)', u'stat': u'fail'}.
我註冊遊離鹼的服務,並增加了瀏覽器的應用程序來查詢的簡單API密鑰:「&鍵= apikeystringhere」。我已經將關鍵問題作爲單獨問題添加了:Setup api key for freebase queries from appengine