Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52080

Re: HTTP post with urllib2

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.027
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'urllib2': 0.07; 'here?': 0.09; 'req': 0.09; 'cc:addr:python-list': 0.11; '6:52': 0.16; 'lambda:': 0.16; 'subject:post': 0.16; 'timeout)': 0.16; 'url.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'this:': 0.26; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'host': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'easier': 0.31; 'requests': 0.31; "skip:' 10": 0.31; '13,': 0.31; 'skip:= 40': 0.31; 'file': 0.32; 'open': 0.33; 'url:python': 0.33; '(most': 0.33; 'skip:# 10': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'subject:with': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'data,': 0.36; 'url:listinfo': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'thank': 0.38; 'pm,': 0.38; 'recent': 0.39; 'does': 0.39; 'url:mail': 0.40; 'skip:u 10': 0.60; 'to:addr:gmail.com': 0.65; 'world': 0.66; 'url:f': 0.68; '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=duymdvGpRBDy/Kky5e9HX2L37FwBpNtH7B5XChPN0mY=; b=gRYXtZoDcMelDGIqhskjpMJWBBDCuo9u/66KgYYfG/s0kqHLl6D+B1VZu1jbbOjInU RLDh+ZFCc2ACcG7vRaalGEffKBtKtA3VZB9EsEdj0GwlO+x0cCgo/nH3/OnSkg9tRkZJ V08hAJy/WfbzTpCtkvVY4O7CjOMaB4TzZmomyM9HzoxcDc4Jc8faZOAyD81gNNK1pq6E WtWsupWQcX46nwv2uKWM4MXnETsdrq7GtXuR/osxG0FGtbmSi0EQ3eWztszAtRRf5zvf q7U3kRdGHxRm1vLzxNQzyH9UXOG1h4MckJlNMnrCbmpvihE+/+9KYDys6TNeoWBmyBGp nFxQ==
MIME-Version 1.0
X-Received by 10.220.104.74 with SMTP id n10mr126132vco.74.1375830514590; Tue, 06 Aug 2013 16:08:34 -0700 (PDT)
In-Reply-To <2e3c176d-6cb9-42f9-91a9-6bf0832a69cb@googlegroups.com>
References <2e3c176d-6cb9-42f9-91a9-6bf0832a69cb@googlegroups.com>
Date Tue, 6 Aug 2013 19:08:34 -0400
Subject Re: HTTP post with urllib2
From Joel Goldstick <joel.goldstick@gmail.com>
To cerr <ron.eggler@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc "python-list@python.org" <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 <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.280.1375830517.1251.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375830517 news.xs4all.nl 15908 [2001:888:2000:d::a6]:47946
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52080

Show key headers only | View raw


On Tue, Aug 6, 2013 at 6:52 PM, cerr <ron.eggler@gmail.com> wrote:
> Hi,
>
> Why does this code:
>
> #!/usr/bin/python
>
>
> import urllib2
> from binascii import hexlify, unhexlify
>
> host = "localhost"
> uri="/test.php"
> data ="\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\x64" #Hello World
> url="http://{0}{1}?f=test".format(host, uri)
> req = urllib2.Request(url, data,{'Content-Type': 'application/octet-stream'})
> req.get_method = lambda: 'PUT'

What does the above line do? is it the same as req.get_method = 'PUT'
> response = urllib2.urlopen(req, 120)

the docs say req should be a url.  Is it?
> retval = response.read()
> print "RETVAL "+retval
>
>
>
> return me this:
>
> ./post.py
> Traceback (most recent call last):
>   File "./post.py", line 13, in <module>
>     response = urllib2.urlopen(req, 120)
>   File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
>     return _opener.open(url, data, timeout)
>   File "/usr/lib/python2.7/urllib2.py", line 398, in open
>     req = meth(req)
>   File "/usr/lib/python2.7/urllib2.py", line 1116, in do_request_
>     'Content-length', '%d' % len(data))
>
>
> I don't get it, what's going on here?
>
> Thank you!
> --
> http://mail.python.org/mailman/listinfo/python-list

KInda of ducking your questions, but the requests module is a lot
easier to use and
understand:http://docs.python-requests.org/en/latest/



-- 
Joel Goldstick
http://joelgoldstick.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

HTTP post with urllib2 cerr <ron.eggler@gmail.com> - 2013-08-06 15:52 -0700
  Re: HTTP post with urllib2 Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-06 19:08 -0400
    Re: HTTP post with urllib2 cerr <ron.eggler@gmail.com> - 2013-08-06 16:35 -0700
      Re: HTTP post with urllib2 Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-06 19:48 -0400
  Re: HTTP post with urllib2 MRAB <python@mrabarnett.plus.com> - 2013-08-07 01:14 +0100
    Re: HTTP post with urllib2 cerr <ron.eggler@gmail.com> - 2013-08-07 09:20 -0700
  Re: HTTP post with urllib2 Chris Angelico <rosuav@gmail.com> - 2013-08-07 01:28 +0100

csiph-web