Google Chart API, HTTP POST request format.

Tim Harig usernet at ilthio.net
Wed Jan 5 23:26:42 EST 2011


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


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /