Python httplib, request & putrequest

小学园PHP xxy-php at qq.com
Tue Apr 9 06:14:47 EDT 2013


I need to use the python httplib.
 
And i code two sample, the first works, not the second.
 
But what i need is the second.
 
In the second sample, the data seems not be sent correctly.
 
I want to know where is the problem in the second.
 
TIA, Levi
 
Here is my two code:
 
first sample:
 conn=httplib.HTTPConnection(data_host) a_file=open("/home/levi/5","rb") data=a_file.read() a_file.close() conn.request("PUT", "/webhdfs/v1/levi/5?op=CREATE&user.name=levi", data) res=conn.getresponse() print res.status,res.reason print res.msg conn.close() 
And the second:
 conn=httplib.HTTPConnection(data_host) conn.connect() conn.putrequest("PUT","/webhdfs/v1/levi/5?op=CREATE&user.name=levi") conn.endheaders() a_file=open("/home/levi/5","rb") data=a_file.read() a_file.close() conn.send(data) res=conn.getresponse() print res.status,res.reason print res.read() print res.msg conn.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130409/9af59531/attachment.html>


More information about the Python-list mailing list