Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Google Chart API, HTTP POST request format.

Reply
Thread Tools

Google Chart API, HTTP POST request format.

 
 
Slie
Guest
Posts: n/a
 
      01-06-2011

http://code.google.com/apis/chart/do..._requests.html

Google will return a chart in your browser from a URL that you have built. If your URL is bigger then 2K characters it will allow you to submit POST requests.

They gives examples of HTML, JavaScript, and PHP POST requests. Is there a way I can submit a request with Python? Or possibly submit the HTML, JavaScript or PHP using python?(That was a long shot thought). If I do that I would need to find out what to do with the .PNG it gives me.

Am I headed in the right direction, is the above paragraph about submitting an HTML form from my program even logical?

I have read several examples on python post requests but I'm not sure mine needs to be that complicated.


Thank You,
 
Reply With Quote
 
 
 
 
Tim Harig
Guest
Posts: n/a
 
      01-06-2011
On 2011-01-06, Slie <> 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()

 
Reply With Quote
 
 
 
 
Chris Rebert
Guest
Posts: n/a
 
      01-06-2011
On Wed, Jan 5, 2011 at 11:21 PM, Garland Fulton <> wrote:
> On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig <> wrote:
>>
>> On 2011-01-06, Slie <> 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.


http://docs.python.org/py3k/library/...equest.urlopen
Specifically: "This function returns a file-like object" (representing
the stream of data received). Thus, .read() on the file-like object
returns the actual bytes obtained from the given URL.

Cheers,
Chris
--
http://blog.rebertia.com
 
Reply With Quote
 
Tim Harig
Guest
Posts: n/a
 
      01-06-2011
On 2011-01-06, Chris Rebert <> wrote:
> On Wed, Jan 5, 2011 at 11:21 PM, Garland Fulton <> wrote:
>> On Wed, Jan 5, 2011 at 7:26 PM, Tim Harig <> wrote:
>>> * *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',


Sorry I didn't notice this got accidently wrapped when I pasted it.
>>> 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()

>>
>> 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.


For some reason, posts from from this account don't seem to be making it
through the gateway to usenet so I am only seeing what Mr. Rebert has
replied to. If you have asked anything else, I very well may have missed
it.

> http://docs.python.org/py3k/library/...equest.urlopen
> Specifically: "This function returns a file-like object" (representing
> the stream of data received). Thus, .read() on the file-like object
> returns the actual bytes obtained from the given URL.


Mr. Rebert already answed your question; but, I will expand on that a
little bit. One of the great things about the Python language is that it
uses what is commonly known as "duck typing." That is anything object which
provides the same attributes as another object can be used as though it is
actually the second object. It is kind of like an implicit form of
generics that doesn't require a template or an interface.

The Python standard library makes extensive use of duck typing for file
like objects. Any object that provides the proper method attributes can be
given to functions that expect files even though the object is given might
not be the traditional concept of a file on the filesystem. It might be a
stringIO object, a socket file object, or something new that you have
created that supports the required method attributes.

The semantics and documentation for file like objects have changed a
little for python2 vs. python3:

python2: http://docs.python.org/library/stdty...l#file-objects
python3: http://docs.python.org/py3k/library/io.html#io.IOBase

but they still basically work the same way. Much of the Python 3
documentation still refers file objects.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
Re: Google Chart API, HTTP POST request format. Chris Rebert Python 0 01-06-2011 04:52 AM
A real challenge: Create a Gantt-chart-like chart gnewsgroup ASP .Net 4 02-06-2008 02:27 PM
Why getInputStream in a http servlet request isn't getting the datasent by browser HTTP POST action? James Java 3 11-25-2005 11:17 PM
How to enter to .aspx page by http connection using http POST request farazkazmi@gmail.com Java 6 08-29-2005 02:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57