Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42483
| From | "СѧPHP" <xxy-php@qq.com> |
|---|---|
| Subject | Curl and python httplib? |
| Date | 2013-03-30 13:08 +0800 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9.1364842651.17481.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Curl and python httplib? "СѧPHP" <xxy-php@qq.com> - 2013-03-30 13:08 +0800
csiph-web