Re: Curl and python httplib?

Discussion in 'Python' started by Mark Lawrence, Apr 1, 2013.

  1. 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
    Mark Lawrence, Apr 1, 2013
    #1
    1. Advertising

  2. Mark Lawrence

    vasudevram Guest

    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
    vasudevram, Apr 1, 2013
    #2
    1. Advertising

  3. Mark Lawrence

    vasudevram Guest

    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
    vasudevram, Apr 1, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris

    cURL in ASP.NET

    Chris, Dec 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    8,147
    Joerg Jooss
    Dec 19, 2004
  2. ß Ø ® G

    Page Curl Javascript wtd

    ß Ø ® G, Jan 26, 2004, in forum: HTML
    Replies:
    10
    Views:
    6,745
    supermann
    Jun 7, 2007
  3. curl and popen2

    , Feb 2, 2005, in forum: Python
    Replies:
    1
    Views:
    568
    Robey Holderith
    Feb 2, 2005
  4. pakalk
    Replies:
    7
    Views:
    165
    Peter J. Holzer
    Mar 28, 2009
  5. Chris Rebert

    Re: Curl and python httplib?

    Chris Rebert, Mar 29, 2013, in forum: Python
    Replies:
    0
    Views:
    114
    Chris Rebert
    Mar 29, 2013
Loading...

Share This Page