On Tue, 09 Apr 2013 18:20:04 +0800, 小学园PHP wrote: > 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.
It works for me. When I try it on my local webserver, I get the expected 405 "Method Not Allowed". What do you get? Of course, I have had to use a different website, since you don't give us enough information to test your code. Without knowing what data_host is, we have no way of running your code and seeing what it does. Please take the time to give us sample code that we can actually run. You might find it useful to read this page first: http://sscce.org/ Also, in your message, I see dozens of lines of HTML like this: > <pre class="default prettyprint prettyprinted"><code><span > class="pln">conn</span><span class="pun">=</span><span > class="pln">httplib</span><span class="pun">.</span><span > class="typ">HTTPConnection</span><span class="pun">(</span><span > class="pln">data_host</span><span class="pun">)</span><span class="pln"> > a_file</span><span class="pun">=</span><span This is a text-only newsgroup, please do not send so-called "rich text" messages here, use plain text. Among all the many reasons for avoiding HTML posting, the biggest is that it breaks formatting of code. Your code comes out as this unreadable mess: [quote] 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() [end quote] Thank you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list