Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'parameters': 0.04; 'argument': 0.05; 'skip:p 60': 0.07; '#print': 0.09; 'failed:': 0.09; 'preferable': 0.09; 'satisfy': 0.09; 'url:localhost': 0.09; 'cc:addr:python-list': 0.11; 'suggest': 0.14; '307': 0.16; 'guys,': 0.16; 'httplib': 0.16; 'parameters,': 0.16; 'server:': 0.16; 'urllib': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'library': 0.18; 'wed,': 0.18; 'trying': 0.19; 'passing': 0.19; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'instead.': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'generally': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:non-standard http port': 0.33; 'skip:d 20': 0.34; 'problem': 0.35; "can't": 0.35; 'knows': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'url:org': 0.36; 'example,': 0.37; 'project': 0.37; 'server': 0.38; 'pm,': 0.38; 'rather': 0.38; 'skip:c 50': 0.60; 'location:': 0.61; 'making': 0.63; 'between': 0.67; 'mar': 0.68; '500': 0.70; 'curl': 0.84; 'sender:addr:chris': 0.84; "skip:' 130": 0.84; 'url:47': 0.84; 'url:v1': 0.84; 'request:': 0.91; 'url:latest': 0.91; 'url:op': 0.91; 'why?': 0.91; 'to:none': 0.92; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=6IXm6ySIFA/RMwF9cvtGafLtl7jUH5z19j/uLy3wDUA=; b=PDDL/kiM7OjTF4e9+ROG0aFCyt/6pFL61TQXiQGqCOialcbbTiVbRiKpcCbw32DaD9 uhhs0bpTBaGS14FwlJRqnpAF2xFZ1mSOd1fgrzVTHK69EnEcXFdCt189lClS68vG1eLX 65YLEL/x29aCyusMfZHixr5IU/glczqXA/gaA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=6IXm6ySIFA/RMwF9cvtGafLtl7jUH5z19j/uLy3wDUA=; b=bNBuNcztqr0DP9Dbq7kp+TlmaBj0HF+z2/Oq0kBbjqxD6YjzFWfMupTW9Rem/M2AMZ pjaqbzW/Aduc1UrLxSXeNjhDHDao3Kco8Z+jtowEmZvS7WtvZijNgLsxpsdFEdKmObeJ mGeX/QQ4m7KMN81seJZ+93VU7k368XK1oAMXipGLfTjaLOXk65nNc302yJhnYBc7K9JM rUtN+EgZuweSb889JfN00e59/uWJlgR/3ynlJN9v6oRDWIIQI648+l6yt1cNr97X9jkE LNNe6Knit7/PrqtaPuh7umcpAUrGeMX21wXeZFBeZxcatVzjwlSyMENEZhMpv3sVGjv1 ZXog== MIME-Version: 1.0 X-Received: by 10.50.192.201 with SMTP id hi9mr8819691igc.48.1364533099255; Thu, 28 Mar 2013 21:58:19 -0700 (PDT) Sender: chris@rebertia.com In-Reply-To: References: Date: Thu, 28 Mar 2013 21:58:19 -0700 X-Google-Sender-Auth: paz17YpC8whLlgq8iQCEoAa4dNg Subject: Re: Curl and python httplib? From: Chris Rebert Cc: python-list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQnYtUd6Li5xliFCDO7jHB6vykmEWd76DJlM+n8P2nmSjmxM0+Ltb8aiI9u7anCo3JxQ3DZc 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364533107 news.xs4all.nl 6846 [2001:888:2000:d::a6]:43125 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:42221 On Wed, Mar 27, 2013 at 7:54 PM, =E5=B0=8F=E5=AD=A6=E5=9B=ADPHP wrote: > Guys, > > I take a project that need send request to Hadoop by curl. > But now, the curl and pycurl can't satisfy my project. So i need use the > powerful httplib. I would say that `requests` (http://docs.python-requests.org/en/latest/ ) is generally preferable to httplib these days. > But failed. > > my curl request: > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=3DCREATE" > > my return: > HTTP/1.1 307 TEMPORARY_REDIRECT > Content-Type: application/octet-stream > Location: > http://58.53.211.47:50075/webhdfs/v1/levi/7?op=3DCREATE&overwrite=3Dfalse > Content-Length: 0 > Server: Jetty(6.1.26) > > Now, i change the curl request to httplib: > import httplib > import urllib > > params=3Durllib.urlencode({"@op":"CREATE","@user.name":"levi"}) > headers=3D{"Content-type": "application/x-www-form-urlencoded","Accept": > "text/plain"} > conn=3Dhttplib.HTTPConnection("localhost:50070") > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers) > response=3Dconn.getresponse() > print response.status, response.reason > data=3Dresponse.read() > print data > conn.close() > > But it failed: > #print response.status, response.reason > 500 Internal Server Error > #print data > '{"RemoteException":{"exception":"WebApplicationException","javaClassName= ":"javax.ws.rs.WebApplicationException","message":null}}' > > Who knows why? It's OK when i use curl, so where is the problem in httpli= b > method? > Or some other reasons? It's rather hard to say when neither the base URL, nor querystring parameters, nor request body are the same between your curl example and your httplib example, making them rather incomparable. Part of the problem may be that you are passing what may have been intended as querystring parameters (`params`) as the `body` argument to HTTPConnection.request(). In any case, I would suggest trying to use the `requests` library instead. Cheers, Chris