Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Curl and python httplib? (http://www.velocityreviews.com/forums/t959275-re-curl-and-python-httplib.html)

Mark Lawrence 04-01-2013 07:33 PM

Re: Curl and python httplib?
 
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...verwrite=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.nam e":"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":"WebApplicationEx ception","javaClassName":"javax.ws.rs.WebApplicati onException","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


vasudevram 04-01-2013 10:07 PM

Re: Curl and python httplib?
 
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...verwrite=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.nam e":"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":"WebApplicationEx ception","javaClassName":"javax.ws.rs.WebApplicati onException","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


vasudevram 04-01-2013 10:07 PM

Re: Curl and python httplib?
 
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...verwrite=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.nam e":"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":"WebApplicationEx ception","javaClassName":"javax.ws.rs.WebApplicati onException","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



All times are GMT. The time now is 11:22 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.