Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2553
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:using': 0.04; 'python?': 0.07; 'python': 0.07; "(i'm": 0.09; 'be:': 0.09; 'finally:': 0.09; 'sun,': 0.09; 'pm,': 0.11; 'wrote:': 0.14; 'subject:python': 0.15; 'f.close()': 0.16; 'f.read()': 0.16; 'hello:': 0.16; 'send,': 0.16; 'subject:form': 0.16; 'url:urllib': 0.16; 'argument': 0.16; 'url:blog': 0.18; 'processed': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'cheers,': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'itself,': 0.23; 'url:wiki': 0.24; 'says': 0.25; 'parameters': 0.26; 'subject:data': 0.26; 'chris': 0.27; 'message- id:@mail.gmail.com': 0.28; 'changing': 0.29; 'like.': 0.29; 'cc:addr:python.org': 0.31; 'get.': 0.31; 'subject:post': 0.31; 'whereas': 0.31; 'url:library': 0.31; 'import': 0.32; 'done': 0.32; 'url:docs': 0.33; 'uses': 0.34; 'using': 0.34; 'post': 0.34; 'difference': 0.35; 'url:en': 0.35; 'try:': 0.35; 'data': 0.37; 'some': 0.37; 'case': 0.37; 'received:209.85': 0.37; 'url:python': 0.37; 'apr': 0.38; 'http': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'url:org': 0.38; 'so,': 0.38; 'received:209': 0.39; 'how': 0.39; 'form,': 0.40; 'greater': 0.40; 'requests': 0.40; 'would': 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'body': 0.62; 'relevant': 0.66; 'fed': 0.68; 'url:php': 0.79; '10:36': 0.84; 'received:209.85.210.174': 0.84; 'received:mail- iy0-f174.google.com': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=Zf/12d0sw7LH5fiGGyoEhiTkb7VFiW21U1314woxAcs=; b=TQnVjRuBy2m3dnYX5+gXONGEyOAugzdvv3NmKybTINUlflq/WxsEDKWUFsMkPiThL2 09VI0QgNsa7HOCon63NLKHjkzVd2GCXMpmE9ATgEJXVOcVN9h8vgXgro4J+am6PuHJ+a O14OTtMk6fJ5+m+45XROjXDISd4Z7WtsXj8C4= |
| DomainKey-Signature | a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=AbCrctrS0udpjEpgYY5Rf03Lq/d6cbPFJKQooAtMVwmERz0oz2lVEmmeILLwC+DH4O wFVt68iHLmOy6T34jr/F22b6wAfHfRbJuEYA+SvtCV9Zx4mamtr6BbL+uBITFKC1TKeL ujOUIr3QP9xWuMrq2QWRTfBlwKmQaJwqeGcOY= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <4D9958FA.8080606@tysdomain.com> |
| References | <4D9958FA.8080606@tysdomain.com> |
| Date | Sun, 3 Apr 2011 23:24:34 -0700 |
| X-Google-Sender-Auth | _kTcqGbtSdPvg8uSg5NuqSvaQDE |
| Subject | Re: using python to post data to a form |
| From | Chris Rebert <clp2@rebertia.com> |
| To | tyler@tysdomain.com |
| Content-Type | text/plain; charset=UTF-8 |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.184.1301898277.2990.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1301898278 news.xs4all.nl 32470 [::ffff:82.94.164.166]:40014 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:2553 |
Show key headers only | View raw
On Sun, Apr 3, 2011 at 10:36 PM, Littlefield, Tyler <tyler@tysdomain.com> wrote:
> Hello:
> I have some data that needs to be fed through a html form to get validated
> and processed and the like. How can I use python to send data through that
> form, given a specific url? the form says it uses post, but I"m not really
> sure what the difference is.
They're different HTTP request methods:
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods
The key upshot in this case is that GET requests place the parameters
in the URL itself, whereas POST requests place them in the body of the
request.
> would it just be:
> http://mysite.com/bla.php?foo=bar&bar=foo?
No, that would be using GET.
> If so, how do I do that with python?
Sending POST data can be done as follows (I'm changing bar=foo to
bar=qux for greater clarity):
from urllib import urlopen, urlencode
form_data = {'foo' : 'bar', 'bar' : 'qux'}
encoded_data = urlencode(form_data)
try:
# 2nd argument to urlopen() is the POST data to send, if any
f = urlopen('http://mysite.com/bla.php', encoded_data)
result = f.read()
finally:
f.close()
Relevant docs:
http://docs.python.org/library/urllib.html
Cheers,
Chris
--
http://blog.rebertia.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: using python to post data to a form Chris Rebert <clp2@rebertia.com> - 2011-04-03 23:24 -0700
csiph-web