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


Groups > comp.lang.python > #42489 > unrolled thread

Re: Curl and python httplib?

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2013-04-01 20:33 +0100
Last post2013-04-01 15:07 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Curl and python httplib? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-01 20:33 +0100
    Re: Curl and python httplib? vasudevram <vasudevram@gmail.com> - 2013-04-01 15:07 -0700
    Re: Curl and python httplib? vasudevram <vasudevram@gmail.com> - 2013-04-01 15:07 -0700

#42489 — Re: Curl and python httplib?

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-04-01 20:33 +0100
SubjectRe: Curl and python httplib?
Message-ID<mailman.12.1364844730.17481.python-list@python.org>
On 30/03/2013 05:08, Сѧ԰PHP 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.
> But failed.
>
> *my curl request:*
> curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE"
>
> *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=CREATE&overwrite=false
> Content-Length: 0
> Server: Jetty(6.1.26)
>
> *Now, i change the curl request to httplib:*
> import httplib
> import urllib
>
> params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"})
> headers={"Content-type": "application/x-www-form-urlencoded","Accept":
> "text/plain"}
> conn=httplib.HTTPConnection("localhost:50070")
> conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers)
> response=conn.getresponse()
> print response.status, response.reason
> data=response.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
> httplib method?
> Or some other reasons?
> Who can help me change the curl request to httplib edition?
>
> TIA
> Levi
>
>

Try the requests module https://pypi.python.org/pypi/requests/ as if I 
can successfuly use it anybody can :)

-- 
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.

Mark Lawrence

[toc] | [next] | [standalone]


#42509

Fromvasudevram <vasudevram@gmail.com>
Date2013-04-01 15:07 -0700
Message-ID<8b190a41-9870-4eda-bce6-9e0e821e4331@googlegroups.com>
In reply to#42489
On Tuesday, April 2, 2013 1:03:58 AM UTC+5:30, Mark Lawrence wrote:
> On 30/03/2013 05:08, Сѧ԰PHP 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.
> 
> > But failed.
> 
> >
> 
> > *my curl request:*
> 
> > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE"
> 
> >
> 
> > *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=CREATE&overwrite=false
> 
> > Content-Length: 0
> 
> > Server: Jetty(6.1.26)
> 
> >
> 
> > *Now, i change the curl request to httplib:*
> 
> > import httplib
> 
> > import urllib
> 
> >
> 
> > params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"})
> 
> > headers={"Content-type": "application/x-www-form-urlencoded","Accept":
> 
> > "text/plain"}
> 
> > conn=httplib.HTTPConnection("localhost:50070")
> 
> > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers)
> 
> > response=conn.getresponse()
> 
> > print response.status, response.reason
> 
> > data=response.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
> 
> > httplib method?
> 
> > Or some other reasons?
> 
> > Who can help me change the curl request to httplib edition?
> 
> >
> 
> > TIA
> 
> > Levi
> 
> >
> 
> >
> 
> 
> 
> Try the requests module https://pypi.python.org/pypi/requests/ as if I 
> 
> can successfuly use it anybody can :)
> 
> 
> 
> -- 
> 
> If you're using GoogleCrap™ please read this 
> 
> http://wiki.python.org/moin/GoogleGroupsPython.
> 
> 
> 
> Mark Lawrence

Or try httplib2

GIYF

[toc] | [prev] | [next] | [standalone]


#42520

Fromvasudevram <vasudevram@gmail.com>
Date2013-04-01 15:07 -0700
Message-ID<mailman.25.1364856587.17481.python-list@python.org>
In reply to#42489
On Tuesday, April 2, 2013 1:03:58 AM UTC+5:30, Mark Lawrence wrote:
> On 30/03/2013 05:08, Сѧ԰PHP 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.
> 
> > But failed.
> 
> >
> 
> > *my curl request:*
> 
> > curl -i -X PUT "http://localhost:50070/webhdfs/v1/levi/7?op=CREATE"
> 
> >
> 
> > *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=CREATE&overwrite=false
> 
> > Content-Length: 0
> 
> > Server: Jetty(6.1.26)
> 
> >
> 
> > *Now, i change the curl request to httplib:*
> 
> > import httplib
> 
> > import urllib
> 
> >
> 
> > params=urllib.urlencode({"@op":"CREATE","@user.name":"levi"})
> 
> > headers={"Content-type": "application/x-www-form-urlencoded","Accept":
> 
> > "text/plain"}
> 
> > conn=httplib.HTTPConnection("localhost:50070")
> 
> > conn.request("PUT","/webhdfs/v1/levi/7.txt",params,headers)
> 
> > response=conn.getresponse()
> 
> > print response.status, response.reason
> 
> > data=response.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
> 
> > httplib method?
> 
> > Or some other reasons?
> 
> > Who can help me change the curl request to httplib edition?
> 
> >
> 
> > TIA
> 
> > Levi
> 
> >
> 
> >
> 
> 
> 
> Try the requests module https://pypi.python.org/pypi/requests/ as if I 
> 
> can successfuly use it anybody can :)
> 
> 
> 
> -- 
> 
> If you're using GoogleCrap™ please read this 
> 
> http://wiki.python.org/moin/GoogleGroupsPython.
> 
> 
> 
> Mark Lawrence

Or try httplib2

GIYF

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web