Segfault-Inc / Multicorn

Data Access Library
https://multicorn.org/
PostgreSQL License
699 stars 145 forks source link

GoogleFDW not working (?) #199

Closed fluca1978 closed 5 years ago

fluca1978 commented 6 years ago

I'm using PostgreSQL 9.6.5 on FreeBSD 11-Release, Python 2.7. I've installed multicorn succesfully, and Im able to run other FDW.

Now I try to define a google server as follows:

CREATE SERVER google_server
  FOREIGN DATA WRAPPER multicorn
  OPTIONS( wrapper 'multicorn.googlefdw.GoogleFdw' );`

and then define the foreign data table:

CREATE FOREIGN TABLE google_search(  
url text,
title text,
search text )
SERVER google_server;

and try to execute a query:


SELECT * FROM google_search WHERE search = 'postgresql';
ERROR:  Error in python: TypeError
DETAIL:  'NoneType' object has no attribute '__getitem__'

and in the logs I've got:


 [29-2] DETAIL:  Traceback (most recent call last):
 [29-3] 
 [29-4]     File "/usr/local/lib/python2.7/site-packages/multicorn-1.3.3.dev0-py2.7-freebsd-11.1-RELEASE-amd64.egg/multicorn/googlefdw.py", line 21, in google
 [29-5]       hits = data['results']
 [29-6] 
 [29-7]   TypeError: 'NoneType' object has no attribute '__getitem__'
 [29-8] 
 [29-9] STATEMENT:  FETCH FORWARD 20 FROM _psql_cursor
 [30-1] ERROR:  current transaction is aborted, commands ignored until end of transaction block
 [30-2] STATEMENT:  CLOSE _psql_cursor

Sounds to me like it is issuing a wrong query and not getting the result. Am I doing something wtong? Should the code protect against null results?

fluca1978 commented 6 years ago

Work in progress: I've tried to get the result via command line:

wget 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=postgresql'

that provides:

{"responseData": null, "responseDetails": "The Google Web Search API is no longer available. Please migrate to the Google Custom Search API (https://developers.google.com/custom-search/)", "responseStatus": 403}

fluca1978 commented 6 years ago

I suspect the only way is either to abandon the FDW or get an api key https://developers.google.com/api-client-library/python/guide/aaa_apikeys