Google Chart API, HTTP POST request format.

Garland Fulton stackslip at gmail.com
Thu Jan 6 02:21:53 EST 2011


On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig <usernet at ilthio.net> wrote:

> On 2011-01-06, Slie <stackslip at gmail.com> wrote:
> [reformated to <80 columns per RFC 1855 guidelines]
> > I have read several examples on python post requests but I'm not sure
> > mine needs to be that complicated.
>
> >From the HTML example on the page you posted:
>
>    <form action='https://chart.googleapis.com/chart' method='POST'>
>        <input type="hidden" name="cht" value="lc"  />
>        <input type="hidden" name="chtt" value="This is | my chart"  />
>        <input type='hidden' name='chs' value='600x200' />
>        <input type="hidden" name="chxt" value="x,y" />
>        <input type='hidden' name='chd' value='t:40,20,50,20,100'/>
>        <input type="submit"  />
>    </form>
>
> you can retreive the same chart from Python:
>
>    Python 3.1.2 (r312:79147, Oct  9 2010, 00:16:06)
>    [GCC 4.4.4] on linux2
>    Type "help", "copyright", "credits" or "license" for more information.
>    >>> import urllib.request, urllib.parse
>    >>> params = urllib.parse.urlencode({'cht':'lc', 'chtt':'This is | my
>    >>> chart',
>    ...         'chs':'600x200', 'chxt':'x,y', 'chd':'t:40,20,50,20,100'})
>    >>> chart = urllib.request.urlopen('https://chart.googleapis.com/chart
> ',
>    ...         data = params).read()
>    >>> chartFile = open("chart.png", 'wb')
>    >>> chartFile.write(chart)
>    10782
>    >>> chartFile.close()
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Hope this isn't to stupid,

For the
chart = urllib.request.urlopen('https://chart.googleapis.com/chart', data =
params).read()

Where would I find information on why and what the ).read() part does.

Thank you,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110105/934cd74c/attachment-0001.html>


More information about the Python-list mailing list