Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsfeed.freenet.ag!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.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; '"the': 0.07; 'urllib2': 0.07; 'http': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; "'q'": 0.16; 'easier.': 0.16; 'edward': 0.16; 'subject:POST': 0.16; 'urllib': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'module': 0.19; 'input': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; '>': 0.26; 'this:': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:& 60': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'requests': 0.31; 'writes:': 0.31; 'stuff': 0.32; 'url:python': 0.33; '"the': 0.34; 'skip:u 20': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'google': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'example,': 0.37; 'skip:& 10': 0.38; 'pm,': 0.38; 'called': 0.40; 'url:mail': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'john': 0.61; 'jul': 0.74; 'email addr:panix.com': 0.84; 'to:addr:gordon': 0.84; 'bears': 0.91; 'joel': 0.91; 'url:latest': 0.91; '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 :cc:content-type; bh=iXCnanizrU94nb5CkYS1kfhQOmoUo92a1j0QLnFWC9M=; b=bciUKPg5G6YvAz07Cod7wxQyRVTuwaDVbJL6cAWhYzk19TGtBAhgKc0TeBBFjGv8X3 OVqiYkWCXAICt7k6697sBh0Jg3pNEQ2xTlgn4HVYw6iEK+QDv+OpMFy8VNofoh6k1YCT VQMcrdz4h0H7+1lX7eRRfQGk6miFyaO1Dtk2dMNHTI0V09rrdfX7peh9EaNLYMbAhPAj SgfO1wPVSXsTZ/p0fM4azQ6rmdbTxiQB2bP+a6kB8vZHBjfdtrw7XBgP6wt/AaCtaSJg n8c01UOUnUGYxfJzmvcY34xvj3yqMic9LtuAH3Gcjiw2xjQJykA+sffq4keO0dcZdChG Oz2g== MIME-Version: 1.0 X-Received: by 10.58.236.70 with SMTP id us6mr2706565vec.89.1374092814239; Wed, 17 Jul 2013 13:26:54 -0700 (PDT) In-Reply-To: References: <00ec2f9b-fcae-428c-8932-163e653dd71b@googlegroups.com> Date: Wed, 17 Jul 2013 16:26:54 -0400 Subject: Re: Python HTTP POST From: Joel Goldstick To: John Gordon Content-Type: multipart/alternative; boundary=047d7bd6a90614d0c104e1baea91 Cc: "python-list@python.org" 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: 97 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374092817 news.xs4all.nl 15905 [2001:888:2000:d::a6]:42543 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50806 --047d7bd6a90614d0c104e1baea91 Content-Type: text/plain; charset=UTF-8 On Wed, Jul 17, 2013 at 4:15 PM, John Gordon wrote: > In <00ec2f9b-fcae-428c-8932-163e653dd71b@googlegroups.com> Matt Graves < > tunacubes@gmail.com> writes: > > > How would I submit a python HTTP POST request to... for example, go to > > google.com, enter "Pie" into the search box and submit (Search) > > Something like this: > > import urllib > import urllib2 > > # the google form search input box is named 'q' > data = { 'q': 'Pie' } > > response = urllib2.urlopen('http://google.com', urllib.urlencode(data)) > print response.read() > > -- > John Gordon A is for Amy, who fell down the stairs > gordon@panix.com B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > -- > http://mail.python.org/mailman/listinfo/python-list > Many people find urllib and urllib2 to be confusing. There is a module called requests which makes this stuff a lot easier. ymmv http://docs.python-requests.org/en/latest/ -- Joel Goldstick http://joelgoldstick.com --047d7bd6a90614d0c104e1baea91 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Wed, Jul 17, 2013 at 4:15 PM, John Gordon <= gordon@panix.com&= gt; wrote:
In <= 00= ec2f9b-fcae-428c-8932-163e653dd71b@googlegroups.com> Matt Graves <= ;tunacubes@gmail.com> writes:=

> How would I submit a python HTTP POST request to... for example, go to=
> google.com, enter = "Pie" into the search box and submit (Search)

Something like this:

import urllib
import urllib2

# the google form search input box is named 'q'
data =3D { 'q': 'Pie' }

response =3D urllib2.urlopen('http://google.com', urllib.urlencode(data))
print response.read()

--
John Gordon =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = A is for Amy, who fell down the stairs
gordon@panix.com =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0B is for Basil, assaulted by bears
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -- Edward Gorey, "The Gashlycru= mb Tinies"

--
http://mail.python.org/mailman/listinfo/python-list


M= any people find urllib and urllib2 to be confusing.=C2=A0 There is a module= called requests which makes this stuff a lot easier.=C2=A0 ymmv

http://docs.python-requ= ests.org/en/latest/

--
--047d7bd6a90614d0c104e1baea91--