Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.139.MISMATCH!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'read.': 0.03; 'skip:\xa0 30': 0.05; 'column': 0.07; 'json': 0.07; 'method.': 0.07; "subject:' ": 0.07; 'urllib2': 0.07; 'welcome.': 0.07; 'lines.': 0.09; 'means,': 0.09; 'promising': 0.09; 'stating': 0.09; 'valueerror:': 0.09; 'url:blog': 0.10; 'api': 0.11; 'python': 0.11; '2.7': 0.14; 'mostly': 0.14; '>>': 0.16; "'data'": 0.16; "'}'": 0.16; '(char': 0.16; '6:00': 0.16; '8bit%:26': 0.16; 'between.': 0.16; 'bracket': 0.16; 'expecting': 0.16; 'inputs': 0.16; 'ioerror:': 0.16; 'nameerror:': 0.16; 'obj,': 0.16; 'subject:search': 0.16; 'supported.': 0.16; 'then?': 0.16; 'thoughts?': 0.16; 'thread,': 0.16; 'url:json': 0.16; 'url:query': 0.16; 'url:urllib': 0.16; 'urllib': 0.16; '\xa0this': 0.16; 'wrote:': 0.18; 'library': 0.18; 'all,': 0.19; 'trying': 0.19; 'file,': 0.19; 'hacking': 0.19; "skip:' 30": 0.19; 'thu,': 0.19; 'working.': 0.19; 'url:view': 0.20; 'seems': 0.21; 'command': 0.22; '>>>': 0.22; 'example': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'issue.': 0.22; 'saying': 0.22; 'shell': 0.22; 'print': 0.22; 'load': 0.23; 'error': 0.23; '>>>': 0.24; 'parse': 0.24; 'skip:\xa0 20': 0.24; '\xa0so': 0.24; 'decide': 0.24; 'file.': 0.24; 'looks': 0.24; "i've": 0.25; '>': 0.26; 'query': 0.26; 'skip:" 30': 0.26; 'skip:" 40': 0.26; 'this:': 0.26; 'post': 0.26; 'defined': 0.27; 'skip:" 20': 0.27; 'skip:_ 20': 0.27; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'leave': 0.29; 'am,': 0.29; "doesn't": 0.30; 'cool': 0.30; 'document.': 0.30; 'kevin': 0.30; 'newer': 0.30; 'specified': 0.30; 'statement': 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'getting': 0.31; '"",': 0.31; '13,': 0.31; '>>>>': 0.31; 'doc': 0.31; 'gaming': 0.31; 'loads': 0.31; 'search.': 0.31; 'url:05': 0.31; 'file': 0.32; 'there.': 0.32; 'this.': 0.32; 'figure': 0.32; 'another': 0.32; 'text': 0.33; 'open': 0.33; 'worked': 0.33; 'url:python': 0.33; 'guess': 0.33; 'skip:& 30': 0.33; 'subject:time': 0.33; 'close': 0.67; '8bit%:31': 0.68; 'live,': 0.68; 'skip:w 40': 0.68; 'url:en-us': 0.68; 'video,': 0.68; 'home': 0.69; 'url:%1': 0.72; 'url:a': 0.72; 'walk': 0.74; '100%': 0.77; 'honest': 0.78; 'subject:get': 0.81; 'site:': 0.83; '360': 0.84; 'console,': 0.84; 'messed': 0.84; 'movie.': 0.84; 'music,': 0.84; 'off,': 0.84; 'url:50': 0.84; 'url:xbox': 0.84; 'validator': 0.84; 'wrong...': 0.84; '2013,': 0.91; '8bit%:33': 0.91; 'closer.': 0.91; 'sitting': 0.91; 'subject:results': 0.91; 'differences': 0.93; 'social,': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=uUPW+zSsAkgzh05KF5+3658fX4rtMj64qa6v7BZ8m4k=; b=tKGTv25LNFtHgOB0XaoIhP5hVvMs+oAkbpZQs6D28YMSFP8MnHEpJJYHfkp/7rp2v7 0OAoraJRPg20n2UsRc1cXDSV1DxvR8SB1+HXb/SMnu5SMNZUt/Ccejubc+7C6CUcWH0Y GlWFlvMJ1luVYVRiDZgd5iXlo1uHRllQ2nbMwQT6XBHZJrgNePYuencgW+Tax1XwQT27 65jrIdjmNG7wpI9kthOwOf2DNuUScY+TvsZJDLelWdi1Dpxjn9qQ41GWzrxZca215CR9 MHxLi1UY3g6O0j/R3mHI8Xk62gV+TTx7DTT5xZSWI9GcPdtwTAqXDI2StMUWjg4IuhHD uLOg== MIME-Version: 1.0 X-Received: by 10.194.11.72 with SMTP id o8mr2223396wjb.0.1371233997593; Fri, 14 Jun 2013 11:19:57 -0700 (PDT) In-Reply-To: <9B89A4BB-D19A-4623-862D-402EE6856157@studiosola.com> References: <0E172A5A-F6C8-43CC-837A-3107BFDFFFCD@studiosola.com> <1C2B340A-D864-4991-BAA8-B8C35880EF1F@studiosola.com> <79299D98-0369-446B-B0FB-2E944250DEC6@studiosola.com> <9B89A4BB-D19A-4623-862D-402EE6856157@studiosola.com> Date: Fri, 14 Jun 2013 14:19:57 -0400 Subject: Re: Having a hard time to 'get' bing api search results From: "Yves S. Garret" To: Kevin LaTona , python-list@python.org Content-Type: multipart/alternative; boundary=e89a8f234d4954a4f704df214bd9 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 1028 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371234005 news.xs4all.nl 16007 [2001:888:2000:d::a6]:48086 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48202 --e89a8f234d4954a4f704df214bd9 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On Fri, Jun 14, 2013 at 2:04 PM, Kevin LaTona wrote: > > > Sounds like you are missing a closing } json bracket > > > Try a different json validator site to prove your json doc is working. > > > If it's the same doc you sent me last night it worked for me > > so maybe it got messed up moving it around????? > > > > > > On Jun 14, 2013, at 10:53 AM, "Yves S. Garret" > wrote: > > Hi Kevin, still more of the same: > http://bin.cakephp.org/view/1358843680 > > The file _is_ there. I did check the JSON file, in this site: > - http://paulisageek.com/json_validator/ > > I got an error stating this: > expected property name or '}' > > And I don't know what it means, especially if my JSON looks like this: > http://bin.cakephp.org/view/33141714 > > > On Fri, Jun 14, 2013 at 12:40 PM, Kevin LaTona wrot= e: > >> >> import json >> >>> from pprint import pprint >> >>> path =3D '/home/azureuser/temp.json' >> >>> with open(data) as data_file: >> ... data =3D json.load(data_file) >> >> >> >> change this to >> >> >> with open(path) as data_file: >> >> >> >> you need to tell the open command what file path to read. >> >> >> >> >> >> On Jun 14, 2013, at 9:28 AM, "Yves S. Garret" >> wrote: >> >> > Hi Kevin, >> > >> > This is the file. >> > http://bin.cakephp.org/view/1893672423 >> > >> > >> > On Fri, Jun 14, 2013 at 12:20 PM, Kevin LaTona >> wrote: >> > >> > >> > >> >> >> >> Traceback >> >> (most recent call last): >> >> >> >> File >> >> "", line 1, in >> >> >> >> NameError: name 'data' is not defined >> > >> > >> > >> > It looks like it saying it did not open and read your json document. >> > >> > Are you 100% sure that is sitting in your home directory? >> > >> > Trying opening it with nano or some other text editor at that path >> > >> > or try >> > >> > cat /home/azureuser/temp.json >> > >> > and see what you get >> > >> > >> > >> > Your are close=85=85 so close. >> > >> > >> > On Jun 14, 2013, at 9:03 AM, Yves S. Garret >> wrote: >> > >> >> Hi Kevin, >> >> >> >> I'm not sure what I'm doing wrong... this is what I did in the shell >> and the error that I got: >> >> http://bin.cakephp.org/view/49070824 >> >> >> >> I'll keep hacking away at this problem... >> >> >> >> >> >> On Thu, Jun 13, 2013 at 11:26 PM, Kevin LaTona >> wrote: >> >> >> >> both are working for me. >> >> >> >> >> >> >> >> >> >> import json >> >> from pprint import pprint >> >> >> >> path =3D '/Users/yves/ms.json' >> >> >> >> >> >> with open(path) as data_file: >> >> data =3D json.load(data_file) >> >> >> >> >> >> >> >> this will allow you to walk through >> >> >> >> [ list ] requires a number else should be mostly just names pulled >> out of the jSon doc >> >> >> >> Xbox One is a state-of-the art gaming console, a new generation TV an= d >> movie system and a whole lot more. Gone are the days of switching inputs= on >> your TV to play a game or watch a movie. >> >> >> >> >> >> ************* >> >> >> >> >> >> >> >> >> >> print data['d']['results'][0]['Description'] >> >> >> >> >> >> >> >> >> >> pretty print >> >> >> >> >> >> >> >> pprint(data) >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> {u'd': {u'__next': u" >> https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'x= box%20one'&$skip=3D2&$top=3D2 >> ", >> >> u'results': [{u'Description': u'Xbox One is a state-of-the ar= t >> gaming console, a new generation TV and movie system and a whole lot mor= e. >> Gone are the days of switching inputs on your TV to play a game or watch= a >> movie.', >> >> u'DisplayUrl': u' >> www.xbox.com/en-US/xboxone/meet-xbox-one', >> >> u'ID': u'39bc6e59-8323-4275-a992-cb434179e29f', >> >> u'Title': u'Introducing Xbox One', >> >> u'Url': u' >> http://www.xbox.com/en-US/xboxone/meet-xbox-one', >> >> u'__metadata': {u'type': u'WebResult', >> >> u'uri': u" >> https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'x= boxone'&$skip=3D0&$top=3D1"}}, >> >> {u'Description': u'Entertainment is More Amazing >> with Xbox. Official site of Xbox 360 + Kinect. Xbox LIVE, social, games, >> video, music, support', >> >> u'DisplayUrl': u'www.xbox.com/en-US', >> >> u'ID': u'06a3d093-ddb4-418b-b34e-a81a0203d3fb', >> >> u'Title': u'Xbox 360 - Official Site - Xbox.com >> ', >> >> u'Url': u'http://www.xbox.com/en-US/', >> >> u'__metadata': {u'type': u'WebResult', >> >> u'uri': u" >> https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'x= boxone'&$skip=3D1&$top=3D1"}}]}} >> >> [Finished in 0.1s] >> >> >> >> >> >> >> >> >> >> On Jun 13, 2013, at 8:12 PM, "Yves S. Garret" < >> yoursurrogategod@gmail.com> wrote: >> >> >> >>> I don't think that it's the print method. This is me experimenting >> with >> >>> various options: >> >>> http://bin.cakephp.org/view/111535571 >> >>> >> >>> This is the JSON file that I was using: >> >>> http://bin.cakephp.org/view/1423034899 >> >>> >> >>> I'd figure that a JSON file generated by MS would 99.99% of the time >> >>> be a good file... >> >>> >> >>> >> >>> On Thu, Jun 13, 2013 at 11:07 PM, Kevin LaTona >> wrote: >> >>> >> >>> Then with statement is a good thing. >> >>> >> >>> looks like pprint is choking you. >> >>> >> >>> To be honest I have not used pprint much >> >>> >> >>> and just grab jSON doc data as needed direct from doc. >> >>> >> >>> print data['some_name'] ( fill in json doc key name ) should get >> it. >> >>> >> >>> >> >>> My guess is you will need to just look at json doc and figure out th= e >> pattern you need. >> >>> >> >>> >> >>> >> >>> Have you done much work direct with JSON docs? >> >>> >> >>> Stackoverflow will have tons of example to help you along those line= s. >> >>> >> >>> >> >>> >> >>> On Jun 13, 2013, at 7:53 PM, Yves S. Garret < >> yoursurrogategod@gmail.com> wrote: >> >>> >> >>>> I should have mentioned it earlier, but I'm using Python 2.7.5. >> >>>> >> >>>> >> >>>> On Thu, Jun 13, 2013 at 9:43 PM, Kevin LaTona >> wrote: >> >>>> >> >>>> >> >>>> if your json doc is valid json >> >>>> >> >>>> try using this code as an example if you are using 2.7 + >> >>>> >> >>>> The With statement is very cool as when you leave it will close the >> JSon doc for you. >> >>>> >> >>>> >> >>>> >> >>>> http://stackoverflow.com/a/13633860 >> >>>> >> >>>> import >> >>>> json >> >>>> >> >>>> from pprint import >> >>>> pprint >> >>>> >> >>>> >> >>>> with open('data.json') as data_file: >> >>>> >> >>>> data >> >>>> =3D json.load(data_file) >> >>>> >> >>>> pprint >> >>>> (data) >> >>>> >> >>>> >> >>>> >> >>>> >> >>>> >> >>>> >> >>>> On Jun 13, 2013, at 6:00 PM, Yves S. Garret < >> yoursurrogategod@gmail.com> wrote: >> >>>> >> >>>>> Thanks again Kevin. I'm deviating from the original thread, >> >>>>> but I've got another issue. When I try to load the json file >> >>>>> and then parse it, this is the error that I get: >> >>>>> http://bin.cakephp.org/view/1329549559 >> >>>>> >> >>>>> >> >>>>> On Thu, Jun 13, 2013 at 6:57 PM, Kevin LaTona >> wrote: >> >>>>> >> >>>>> >> >>>>> Your welcome. >> >>>>> >> >>>>> >> >>>>> To be honest I am not 100% on the differences between. >> >>>>> >> >>>>> I could be off, but I recall urllib2 was a more refined version of >> urllib. >> >>>>> >> >>>>> Yet it seems like urllib works better for me, when I need to do a >> simple call like this. >> >>>>> >> >>>>> >> >>>>> -Kevin >> >>>>> >> >>>>> >> >>>>> >> >>>>> On Jun 13, 2013, at 3:50 PM, "Yves S. Garret" < >> yoursurrogategod@gmail.com> wrote: >> >>>>> >> >>>>>> That works beautifully! Thank you! >> >>>>>> >> >>>>>> I do have one question, what are urllib and urllib2 then? I >> figured that >> >>>>>> urllib2 is a newer version of the previous library (and one that = I >> should >> >>>>>> be using). Am I missing something? >> >>>>>> >> >>>>>> >> >>>>>> On Thu, Jun 13, 2013 at 6:45 PM, Kevin LaTona < >> lists@studiosola.com> wrote: >> >>>>>> >> >>>>>> I did a quick test with url lib instead of urllib2 and got closer= . >> >>>>>> >> >>>>>> Problem right now is without ID code I can't check any further. >> >>>>>> >> >>>>>> But it does look promising at this point. >> >>>>>> >> >>>>>> >> >>>>>> If all else fails >> http://docs.python.org/2/library/urllib.html#examples >> >>>>>> >> >>>>>> >> >>>>>> import urllib >> >>>>>> >> >>>>>> f =3D urllib.urlopen(' >> https://user:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@api.datamarket.= azure.com/Bing/SearchWeb/Web?Query=3D%27xbox%20one%27&$top=3D50&$format=3DJ= SON >> ') >> >>>>>> >> >>>>>> print f.read() >> >>>>>> >> >>>>>> >> >>>>>> >> >>>>>> IOError: ('http error', 401, 'The authorization type you provided >> is not supported. Only Basic and OAuth are supported', >> >>>>>> >> >>>>>> >> >>>>>> >> >>>>>> >> >>>>>> >> >>>>>> On Jun 13, 2013, at 2:31 PM, Yves S. Garret < >> yoursurrogategod@gmail.com> wrote: >> >>>>>> >> >>>>>>> This is the format that I've been following: >> >>>>>>> >> http://gavinmhackeling.com/blog/2012/05/using-the-bing-search-api-in-pyt= hon/ >> >>>>>>> >> >>>>>>> If I execute the specified query from a browser, the JSON file >> >>>>>>> shows up without a problem. Now, I'd like to do that >> programmatically. >> >>>>>>> >> >>>>>>> >> >>>>>>> On Thu, Jun 13, 2013 at 4:57 PM, Yves S. Garret < >> yoursurrogategod@gmail.com> wrote: >> >>>>>>> Hello all, >> >>>>>>> >> >>>>>>> This is my dilemma, I'm trying to get the generated JSON file >> using the bing api >> >>>>>>> search. >> >>>>>>> >> >>>>>>> This is the code that I'm executing from inside the shell: >> >>>>>>> http://bin.cakephp.org/view/460660617 >> >>>>>>> >> >>>>>>> The port doesn't matter to me. Thoughts? >> >>>>>>> >> >>>>>>> -- >> >>>>>>> http://mail.python.org/mailman/listinfo/python-list >> >>>>>> >> >>>>>> >> >>>>> >> >>>>> >> >>>> >> >>>> >> >>> >> >>> >> >> >> >> >> > >> > >> >> > > Ooops, I think we've left the mailing list off of this one. This is the error that I'm getting right now. >>> import json >>> from pprint import pprint >>> path =3D '/home/azureuser/temp.json' >>> with open(path) as data_file: ... data =3D json.load(data_file) ... Traceback (most recent call last): File "", line 2, in File "/usr/local/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/usr/local/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/usr/local/lib/python2.7/json/decoder.py", line 365, in decode obj, end =3D self.raw_decode(s, idx=3D_w(s, 0).end()) File "/usr/local/lib/python2.7/json/decoder.py", line 381, in raw_decode obj, end =3D self.scan_once(s, idx) ValueError: Expecting property name: line 2 column 1 (char 2) Thanks for your inputs Andreas. Also, this is my JSON file, I'll post again. Since it's going to be messy, I'll include a link as well (users can decide what they prefer to read). http://bin.cakephp.org/view/1050217914 { "d": { "results": [ { "__metadata": { "uri": " https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox= one'&$skip=3D0&$top=3D1", "type": "WebResult" }, "ID": "39bc6e59-8323-4275-a992-cb434179e29f", "Title": "Introducing Xbox One", "Description": "Xbox One is a state-of-the art gaming console, a new generation TV and movie system and a whole lot more. Gone are the days of switching inputs on your TV to play a game or watch a movie.", "DisplayUrl": "www.xbox.com/en-US/xboxone/meet-xbox-one", "Url": "http://www.xbox.com/en-US/xboxone/meet-xbox-one" }, { "__metadata": { "uri": " https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox= one'&$skip=3D1&$top=3D1", "type": "WebResult" }, "ID": "06a3d093-ddb4-418b-b34e-a81a0203d3fb", "Title": "Xbox 360 - Official Site - Xbox.com", "Description": "Entertainment is More Amazing with Xbox. Official site of Xbox 360 + Kinect. Xbox LIVE, social, games, video, music, support"= , "DisplayUrl": "www.xbox.com/en-US", "Url": "http://www.xbox.com/en-US/" } ], "__next": " https://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox= %20one'&$skip=3D2&$top=3D2 " } } --e89a8f234d4954a4f704df214bd9 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable
On F= ri, Jun 14, 2013 at 2:04 PM, Kevin LaTona <kl@studiosola.com> wrote:


Sounds like you are missing a= closing } json bracket


Try a different json validator site to p= rove your json doc is working.


If i= t's the same doc you sent me last night it worked for me

=A0so maybe it got messed up moving it around?????





On Jun 14, 2013, at 10:53 AM, "Yves S. Garret" = <yoursur= rogategod@gmail.com> wrote:

Hi Kevin, sti= ll more of the same:
http://bin.cakephp.org/view/1358843680

T= he file _is_ there.=A0 I did check the JSON file, in this site:
- http= ://paulisageek.com/json_validator/

I got an error stating = this:
expected property name or '}'

And I don't= know what it means, especially if my JSON looks like this:
http://b= in.cakephp.org/view/33141714

On Fri, Jun 14, 2013 at 12:40 PM, Kevin LaTona= <lists@studiosola.com> wrote:

=A0import json
>>> from pprint import pprint
>>> path =3D '/home/azureuser/temp.json'
>>> with open(data) as data_file:
... =A0 data =3D json.load(data_file)



change this to


with open(path) as data_file:



you need to tell the open command what file path to read.





On Jun 14, 2013, at 9:28 AM, "Yves S. Garret" <yoursurrogategod@gmail.com= > wrote:

> Hi Kevin,
>
> This is the file.
> h= ttp://bin.cakephp.org/view/1893672423
>
>
> On Fri, Jun 14, 2013 at 12:20 PM, Kevin LaTona <kl@studiosola.com> wrote:
>
>
>
>>
>> Traceback
>> (most recent call last):
>>
>> =A0 File
>> "<stdin>", line 1, in <module>
>>
>> NameError: name 'data' is not defined
>
>
>
> It looks like it saying it did not open and read your json document. >
> Are you 100% sure that is sitting in your home directory?
>
> Trying opening it with nano or some other text editor at that path
>
> or try
>
> cat /home/azureuser/temp.json
>
> and see what you get
>
>
>
> Your are close=85=85 so close.
>
>
> On Jun 14, 2013, at 9:03 AM, Yves S. Garret <yoursurrogategod@gmail.com>= ; wrote:
>
>> Hi Kevin,
>>
>> I'm not sure what I'm doing wrong... this is what I did in= the shell and the error that I got:
>> http://bin.cakephp.org/view/49070824
>>
>> I'll keep hacking away at this problem...
>>
>>
>> On Thu, Jun 13, 2013 at 11:26 PM, Kevin LaTona <lists@studiosola.com> wro= te:
>>
>> both are working for me.
>>
>>
>>
>>
>> import json
>> from pprint import pprint
>>
>> path =3D '/Users/yves/ms.json'
>>
>>
>> with open(path) as data_file:
>> =A0 =A0 data =3D json.load(data_file)
>>
>>
>>
>> this will allow you to walk through
>>
>> [ list ] =A0requires a number else should be mostly just names pul= led out of the jSon doc
>>
>> Xbox One is a state-of-the art gaming console, a new generation TV= and movie system and a whole lot more. Gone are the days of switching inpu= ts on your TV to play a game or watch a movie.
>>
>>
>> *************
>>
>>
>>
>>
>> print data['d']['results'][0]['Description'= ;]
>>
>>
>>
>>
>> pretty print
>>
>>
>>
>> pprint(data)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> {u'd': {u'__next': u"https://api.datamarket.azu= re.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox%20one'&$skip= =3D2&$top=3D2",
>> =A0 =A0 =A0 =A0 u'results': [{u'Description': u= 9;Xbox One is a state-of-the art gaming console, a new generation TV and mo= vie system and a whole lot more. Gone are the days of switching inputs on y= our TV to play a game or watch a movie.',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'DisplayUrl':= u'www.xbox.com/en-US/xboxone/meet-xbox-one',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'ID': u'3= 9bc6e59-8323-4275-a992-cb434179e29f',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'Title': u= 9;Introducing Xbox One',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'Url': u'= http://www.xbox.com/en-US/xboxone/meet-xbox-one',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'__metadata':= {u'type': u'WebResult',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 u'uri': u"https= ://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox<= /a> one'&$skip=3D0&$top=3D1"}},
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{u'Description'= : u'Entertainment is More Amazing with Xbox. Official site of Xbox 360 = + Kinect. Xbox LIVE, social, games, video, music, support',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'DisplayUrl':= u'
www.xbox.com= /en-US',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'ID': u'0= 6a3d093-ddb4-418b-b34e-a81a0203d3fb',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'Title': u= 9;Xbox 360 - Official Site - = Xbox.com',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'Url': u'= http://www.xbox.co= m/en-US/',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 u'__metadata':= {u'type': u'WebResult',
>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 u'uri': u"https= ://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox<= /a> one'&$skip=3D1&$top=3D1"}}]}}
>> [Finished in 0.1s]
>>
>>
>>
>>
>> On Jun 13, 2013, at 8:12 PM, "Yves S. Garret" <
yoursurrogategod@= gmail.com> wrote:
>>
>>> I don't think that it's the print method. =A0This is m= e experimenting with
>>> various options:
>>> http://bin.cakephp.org/view/111535571
>>>
>>> This is the JSON file that I was using:
>>> http://bin.cakephp.org/view/1423034899
>>>
>>> I'd figure that a JSON file generated by MS would 99.99% o= f the time
>>> be a good file...
>>>
>>>
>>> On Thu, Jun 13, 2013 at 11:07 PM, Kevin LaTona <lists@studiosola.com>= wrote:
>>>
>>> Then with statement is a good thing.
>>>
>>> looks like pprint is choking you.
>>>
>>> To be honest I have not used pprint much
>>>
>>> and just grab jSON doc data as needed direct from doc.
>>>
>>> print data['some_name'] =A0 ( fill in json doc key nam= e ) =A0should get it.
>>>
>>>
>>> My guess is you will need to just look at json doc and figure = out the pattern you need.
>>>
>>>
>>>
>>> Have you done much work direct with JSON docs?
>>>
>>> Stackoverflow will have tons of example to help you along thos= e lines.
>>>
>>>
>>>
>>> On Jun 13, 2013, at 7:53 PM, Yves S. Garret <yoursurrogategod@gmail.co= m> wrote:
>>>
>>>> I should have mentioned it earlier, but I'm using Pyth= on 2.7.5.
>>>>
>>>>
>>>> On Thu, Jun 13, 2013 at 9:43 PM, Kevin LaTona <lists@studiosola.com= > wrote:
>>>>
>>>>
>>>> if your json doc is valid json
>>>>
>>>> try using this code as an example if you are using 2.7 + >>>>
>>>> The With statement is very cool as when you leave it will = close the JSon doc for you.
>>>>
>>>>
>>>>
>>>> http://stackoverflow.com/a/13633860
>>>>
>>>> import
>>>> =A0json
>>>>
>>>> from pprint import
>>>> =A0pprint
>>>>
>>>>
>>>> with open('data.json') as data_file:
>>>>
>>>> =A0 =A0 data
>>>> =3D json.load(data_file)
>>>>
>>>> pprint
>>>> (data)
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Jun 13, 2013, at 6:00 PM, Yves S. Garret <yoursurrogategod@gmai= l.com> wrote:
>>>>
>>>>> Thanks again Kevin. =A0I'm deviating from the orig= inal thread,
>>>>> but I've got another issue. =A0When I try to load = the json file
>>>>> and then parse it, this is the error that I get:
>>>>> http://bin.cakephp.org/view/1329549559
>>>>>
>>>>>
>>>>> On Thu, Jun 13, 2013 at 6:57 PM, Kevin LaTona <lists@studiosola.com<= /a>> wrote:
>>>>>
>>>>>
>>>>> Your welcome.
>>>>>
>>>>>
>>>>> To be honest I am not 100% on the differences between.=
>>>>>
>>>>> I could be off, but I recall urllib2 was a more refine= d version of urllib.
>>>>>
>>>>> Yet it seems like urllib works better for me, when I n= eed to do a simple call like this.
>>>>>
>>>>>
>>>>> -Kevin
>>>>>
>>>>>
>>>>>
>>>>> On Jun 13, 2013, at 3:50 PM, "Yves S. Garret"= ; <
yours= urrogategod@gmail.com> wrote:
>>>>>
>>>>>> That works beautifully! =A0Thank you!
>>>>>>
>>>>>> I do have one question, what are urllib and urllib= 2 then? =A0I figured that
>>>>>> urllib2 is a newer version of the previous library= (and one that I should
>>>>>> be using). =A0Am I missing something?
>>>>>>
>>>>>>
>>>>>> On Thu, Jun 13, 2013 at 6:45 PM, Kevin LaTona <= lists@studiosola.= com> wrote:
>>>>>>
>>>>>> I did a quick test with url lib instead of urllib2= and got closer.
>>>>>>
>>>>>> Problem right now is without ID code I can't c= heck any further.
>>>>>>
>>>>>> But it does look promising at this point.
>>>>>>
>>>>>>
>>>>>> If all else fails http://docs.python.org/= 2/library/urllib.html#examples
>>>>>>
>>>>>>
>>>>>> import urllib
>>>>>>
>>>>>> f =3D urllib.urlopen('https://user:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA@api= .datamarket.azure.com/Bing/SearchWeb/Web?Query=3D%27xbox%20one%27&$top= =3D50&$format=3DJSON')
>>>>>>
>>>>>> print f.read()
>>>>>>
>>>>>>
>>>>>>
>>>>>> IOError: ('http error', 401, 'The auth= orization type you provided is not supported. =A0Only Basic and OAuth are s= upported',
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Jun 13, 2013, at 2:31 PM, Yves S. Garret <yoursurrogate= god@gmail.com> wrote:
>>>>>>
>>>>>>> This is the format that I've been followin= g:
>>>>>>> http://gavinmh= ackeling.com/blog/2012/05/using-the-bing-search-api-in-python/
>>>>>>>
>>>>>>> If I execute the specified query from a browse= r, the JSON file
>>>>>>> shows up without a problem. =A0Now, I'd li= ke to do that programmatically.
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Jun 13, 2013 at 4:57 PM, Yves S. Garre= t <yours= urrogategod@gmail.com> wrote:
>>>>>>> Hello all,
>>>>>>>
>>>>>>> This is my dilemma, I'm trying to get the = generated JSON file using the bing api
>>>>>>> search.
>>>>>>>
>>>>>>> This is the code that I'm executing from i= nside the shell:
>>>>>>> http://bin.cakephp.org/view/460660617
>>>>>>>
>>>>>>> The port doesn't matter to me. =A0Thoughts= ?
>>>>>>>
>>>>>>> --
>>>>>>> http://mail.python.org/mailman/listinfo= /python-list
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>




Ooops, I th= ink we've left the mailing list off of this one.

This is the error that I'm getting right now.
>= >> import json
>>> from pprint import pprint
>>> path =3D '/home/= azureuser/temp.json'
>>> with open(path) as data_file:
.= ..=A0=A0 data =3D json.load(data_file)
...
Traceback (most recent ca= ll last):
=A0 File "<stdin>", line 2, in <module>
=A0 File &= quot;/usr/local/lib/python2.7/json/__init__.py", line 290, in load
= =A0=A0=A0 **kw)
=A0 File "/usr/local/lib/python2.7/json/__init__.py= ", line 338, in loads
=A0=A0=A0 return _default_decoder.decode(s)
=A0 File "/usr/local/li= b/python2.7/json/decoder.py", line 365, in decode
=A0=A0=A0 obj, en= d =3D self.raw_decode(s, idx=3D_w(s, 0).end())
=A0 File "/usr/local= /lib/python2.7/json/decoder.py", line 381, in raw_decode
=A0=A0=A0 obj, end =3D self.scan_once(s, idx)
ValueError: Expecting prop= erty name: line 2 column 1 (char 2)

Thanks for your inputs Andreas.

Al= so, this is my JSON file, I'll post again.=A0 Since it's going to b= e
messy, I'll include a link as well (users can decide what they preferto read).
http://bi= n.cakephp.org/view/1050217914

{
=A0=A0"d": {
=A0= =A0=A0=A0"results": [
=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0"__metadata": {=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0"uri": "http= s://api.datamarket.azure.com/Data.ashx/Bing/SearchWeb/Web?Query=3D'xbox= one'&$skip=3D0&$top=3D1",
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0"type": "WebResult"
= =A0=A0=A0=A0=A0=A0=A0=A0},
=A0=A0=A0=A0=A0=A0=A0=A0"ID": "= ;39bc6e59-8323-4275-a992-cb434179e29f",
=A0=A0=A0=A0=A0=A0=A0=A0&qu= ot;Title": "Introducing Xbox One",
=A0=A0=A0=A0=A0=A0=A0= =A0"Description": "Xbox One is a state-of-the art gaming con= sole, a new generation TV and movie system and a whole lot more. Gone are t= he days of switching inputs on your TV to play a game or watch a movie.&quo= t;,
=A0=A0=A0=A0=A0=A0=A0=A0"DisplayUrl": "www.xbox.com/en-US/xboxone/meet-xbox= -one",
=A0=A0=A0=A0=A0=A0=A0=A0"Url": "http://www.xbox.com/en= -US/xboxone/meet-xbox-one"
=A0=A0=A0=A0=A0=A0},
=A0=A0=A0=A0=A0=A0{
=A0=A0=A0=A0=A0=A0=A0=A0&quo= t;__metadata": {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0"uri": &qu= ot;https://api.datamarket.azure.com/Data.ashx/Bing/SearchW= eb/Web?Query=3D'xbox one'&$skip=3D1&$top=3D1",
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0"type": "WebResult"
= =A0=A0=A0=A0=A0=A0=A0=A0},
=A0=A0=A0=A0=A0=A0=A0=A0"ID": "= ;06a3d093-ddb4-418b-b34e-a81a0203d3fb",
=A0=A0=A0=A0=A0=A0=A0=A0&qu= ot;Title": "Xbox 360 - Official Site - Xbox.com",
=A0=A0=A0=A0=A0=A0=A0=A0"Description": "Entertainment is Mor= e Amazing with Xbox. Official site of Xbox 360 + Kinect. Xbox LIVE, social,= games, video, music, support",
=A0=A0=A0=A0=A0=A0=A0=A0"Displ= ayUrl": "www.xbox.com/en-US= ",
=A0=A0=A0=A0=A0=A0=A0=A0"Url": "http://www.xbox.com/en-US/"
=A0=A0=A0=A0=A0=A0}
= =A0=A0=A0=A0],
=A0=A0=A0=A0"__next": "https://api.datamarket.azure.com/Data.a= shx/Bing/SearchWeb/Web?Query=3D'xbox%20one'&$skip=3D2&$top= =3D2"
=A0=A0}
}
--e89a8f234d4954a4f704df214bd9--