Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52092
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.014 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'none,': 0.07; 'urllib2': 0.07; 'here?': 0.09; 'req': 0.09; "'data'": 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'lambda:': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'subject:post': 0.16; 'timeout)': 0.16; 'wrote:': 0.18; 'import': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'skip:" 30': 0.26; 'this:': 0.26; 'code:': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'host': 0.29; "skip:' 10": 0.31; '13,': 0.31; 'skip:= 40': 0.31; 'file': 0.32; 'open': 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; 'data,': 0.36; 'words,': 0.36; 'hi,': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; "you're": 0.61; 'world': 0.66; 'header:Reply-To:1': 0.67; 'url:f': 0.68; 'reply- to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=Nmpl7koqW6YA:10 a=nUl_Fy5eI4XtoEz0XWQA:9 a=wPNLvfGTeEIA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Wed, 07 Aug 2013 01:14:48 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: HTTP post with urllib2 |
| References | <2e3c176d-6cb9-42f9-91a9-6bf0832a69cb@googlegroups.com> |
| In-Reply-To | <2e3c176d-6cb9-42f9-91a9-6bf0832a69cb@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| 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.288.1375834490.1251.python-list@python.org> (permalink) |
| Lines | 47 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1375834490 news.xs4all.nl 15939 [2001:888:2000:d::a6]:60389 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52092 |
Show key headers only | View raw
On 06/08/2013 23:52, cerr 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'
> response = urllib2.urlopen(req, 120)
> 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?
>
The docs say """urllib2.urlopen(url[, data][, timeout])""".
You're calling it as """urllib2.urlopen(req, 120)""".
In other words, 'url' is req and 'data' is 120.
It should be """urllib2.urlopen(req, None, 120)""".
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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