Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'url:pypi': 0.03; 'skip:p 60': 0.07; '#print': 0.09; 'lawrence': 0.09; 'satisfy': 0.09; 'to:addr:comp.lang.python': 0.09; 'url:localhost': 0.09; 'cc:addr :python-list': 0.11; '307': 0.16; 'guys,': 0.16; 'httplib': 0.16; 'server:': 0.16; 'urllib': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'module': 0.19; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'url:moin': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'requests': 0.31; 'url:wiki': 0.31; 'url:python': 0.33; 'url:non-standard http port': 0.33; 'skip:d 20': 0.34; 'problem': 0.35; "can't": 0.35; 'received:209.85': 0.35; 'knows': 0.35; 'anybody': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'project': 0.37; 'received:209': 0.37; 'server': 0.38; 'read': 0.60; 'skip:c 50': 0.60; 'location:': 0.61; "you're": 0.61; '500': 0.70; 'curl': 0.84; "skip:' 130": 0.84; 'url:47': 0.84; 'url:v1': 0.84; 'url:op': 0.91; 'why?': 0.91; '2013': 0.98 X-Received: by 10.50.53.232 with SMTP id e8mr1342978igp.14.1364854061062; Mon, 01 Apr 2013 15:07:41 -0700 (PDT) Newsgroups: comp.lang.python Date: Mon, 1 Apr 2013 15:07:40 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=14.96.164.226; posting-account=9tO8owkAAAA3FGTpR0gRxfE7SAV9In1Y References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 14.96.164.226 MIME-Version: 1.0 Subject: Re: Curl and python httplib? From: vasudevram To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: , Message-ID: Lines: 125 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364856587 news.xs4all.nl 6962 [2001:888:2000:d::a6]:39704 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42520 On Tuesday, April 2, 2013 1:03:58 AM UTC+5:30, Mark Lawrence wrote: > On 30/03/2013 05:08, =D0=A1=D1=A7=D4=B0PHP wrote: >=20 > > Guys, >=20 > > >=20 > > I take a project that need send request to Hadoop by curl. >=20 > > But now, the curl and pycurl can't satisfy my project. So i need use th= e >=20 > > powerful httplib. >=20 > > But failed. >=20 > > >=20 > > *my curl request:* >=20 > > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=3DCREATE" >=20 > > >=20 > > *my return:* >=20 > > HTTP/1.1 307 TEMPORARY_REDIRECT >=20 > > Content-Type: application/octet-stream >=20 > > Location: >=20 > > http://58.53.211.47:50075/webhdfs/v1/levi/7?op=3DCREATE&overwrite=3Dfal= se >=20 > > Content-Length: 0 >=20 > > Server: Jetty(6.1.26) >=20 > > >=20 > > *Now, i change the curl request to httplib:* >=20 > > import httplib >=20 > > import urllib >=20 > > >=20 > > params=3Durllib.urlencode({"@op":"CREATE","@user.name":"levi"}) >=20 > > headers=3D{"Content-type": "application/x-www-form-urlencoded","Accept"= : >=20 > > "text/plain"} >=20 > > conn=3Dhttplib.HTTPConnection("localhost:50070") >=20 > > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) >=20 > > response=3Dconn.getresponse() >=20 > > print response.status, response.reason >=20 > > data=3Dresponse.read() >=20 > > print data >=20 > > conn.close() >=20 > > >=20 > > *But it failed:* >=20 > > #print response.status, response.reason >=20 > > 500 Internal Server Error >=20 > > #print data >=20 > > '{"RemoteException":{"exception":"WebApplicationException","javaClassNa= me":"javax.ws.rs.WebApplicationException","message":null}}' >=20 > > >=20 > > Who knows why? It's OK when i use curl, so where is the problem in >=20 > > httplib method? >=20 > > Or some other reasons? >=20 > > Who can help me change the curl request to httplib edition? >=20 > > >=20 > > TIA >=20 > > Levi >=20 > > >=20 > > >=20 >=20 >=20 > Try the requests module https://pypi.python.org/pypi/requests/ as if I=20 >=20 > can successfuly use it anybody can :) >=20 >=20 >=20 > --=20 >=20 > If you're using GoogleCrap=E2=84=A2 please read this=20 >=20 > http://wiki.python.org/moin/GoogleGroupsPython. >=20 >=20 >=20 > Mark Lawrence Or try httplib2 GIYF