[Developers] Python query not working?

David Flanagan david at davidflanagan.com
Tue Jul 22 19:23:06 UTC 2008


In addition to restoring the square brackets, you've also got to do one 
more thing.

You started writing this program by cutting-and-pasting a string of JSON 
text.  That string of text happens to also be a legal JavaScript program 
fragment.  But it is not Python code, so you can't just paste it into a 
Python program.  To translate it to Python, change null to None, true to 
True, and false to False.

Also, you'll notice that the query you cut-and-pasted has all of its 
forward slashes escaped by backslashes.  I've never understood why JSON 
serializers do this, and I'm concerned that the backslashes will mess up 
your query when they go through the JSON serialization process again. 
So I think you'd better remove those, too.

	David Flanagan

Chris Mahon wrote:
> Hi Chris,
> 
> This is the code. I removed the first [ bracket at the beginning/end. 
> I'm not at my dev box at the moment to tell you the error, will be later.
> 
> Using Django and Python 2.4 if that helps?
> 
> CODE
> ======
> from freebase.api import HTTPMetawebSession, MetawebError
> 
> query = {  "sort": "s0:type.link.timestamp.value",
>     "publisher": {
>       "optional": true,
>       "name": null,
>       "id": null
>     },
>     "version_specific_name": null,
>     "!q2284:\/cvg\/cvg_platform\/games_on_this_platform": [
>       {
>         "id": "\/en\/xbox_360"
>       }
>     ],
>     "s0:type": [
>       {
>         "link": [
>           {
>             "timestamp": [
>               {
>                 "type": "\/type\/datetime",
>                 "value": null
>               }
>             ],
>             "type": "\/type\/link"
>           }
>         ],
>         "type": "\/type\/type",
>         "id": "\/cvg\/game_version"
>       }
>     ],
>     "regions": [
>       {
>         "name": null,
>         "optional": true,
>         "id!=": "\/en\/xbox_360",
>         "limit": 6,
>         "type": "\/cvg\/computer_game_region",
>         "id": null
>       }
>     ],
>     "game": {
>       "optional": true,
>       "name": null,
>       "id": null
>     },
>     "limit": 30,
>     "type": "\/cvg\/game_version",
>     "id": null,
>     "developer": {
>       "optional": true,
>       "name": null,
>       "id": null
>     }
> }
> 
> mss = HTTPMetawebSession('www.freebase.com <http://www.freebase.com>')
> result = mss.mqlread(query)
> 
> for game in result.game:
>     print game
> 
> On Tue, Jul 22, 2008 at 3:00 PM, Christopher R. Maden <crism at metaweb.com 
> <mailto:crism at metaweb.com>> wrote:
> 
>     Chris Mahon wrote:
>      > Trying to use the query generated by this page in my Python app:
>      >
>      >
>     http://sandbox.freebase.com/view/en/xbox_360?pid=%2Fcvg%2Fcvg_platform%2Fgames_on_this_platform
>      >
>      > I've clicked on Use Results, and copied the query under "See the
>     query".
>      > I copied the code on this page, but replace the query in it with
>     the one
>      > from the page above:
>      >
>      >
>     http://code.google.com/p/freebase-python/source/browse/trunk/freebase-api/examples/get_albums.py
>      >
>      > I'm using freebase-python, basically just gives me a MQL error. I've
>      > used the basic query that gets all of stings albums, works fine.
>      >
>      > Any ideas?
> 
>     What is the MQL error you are getting?
> 
>     Exactly how did you replace the query in the sample code?  Did you
>     replace the entire Sting query, including the curly braces, with the
>     entire Xbox query, including the square brackets?
> 
>     ~Chris
>     --
>     Christopher R. Maden
>     Data Architect
>     Freebase.com: <URL: http://www.freebase.com/ >
>     Metaweb Technologes, Inc. <URL: http://www.metaweb.com/ >
>     _______________________________________________
>     Developers mailing list
>     Developers at freebase.com <mailto:Developers at freebase.com>
>     http://lists.freebase.com/mailman/listinfo/developers
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers



More information about the Developers mailing list