Question

The following works locally but not when deployed:

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()

When deployed it throws the following error:

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)

It could be related to this problem: freebase api error on deployment to appengine: DownloadError: ApplicationError: 2 in which case adding an api key to the request could fix it. Though my attempt to add a key (using urlfetch) resulted in an error:

{u'code': 100, u'message': u'Invalid API Key (Key not found)', u'stat': u'fail'}. 

I registered the freebase service and added the Simple API key for browser apps to the query: '&key=apikeystringhere'. I've added the key issue as a separate question: Setup api key for freebase queries from appengine

Was it helpful?

Solution 2

I have it working now. It was not working on the remote because I needed a key. My previous attempt to add the key failed because i was using the deprecated http://api.freebase.com API when I should have been using: https://www.googleapis.com/freebase/v1/search?q=bob&key=

OTHER TIPS

Why not use the urlfetch API rather than urllib2?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top