- 论坛徽章:
- 0
|
本帖最后由 meto2009 于 2013-04-06 21:03 编辑
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2
register_openers()
datagen, headers = multipart_encode({'file' pen('test.txt', 'rb')})
request = urllib2.Request('http://127.0.0.1:8080/', datagen, headers)
response = urllib2.urlopen(request)
print response.read()
文件是上传上去了,但是报如下错误信息
Traceback (most recent call last):
File "upload.py", line 9, in <module>
response = urllib2.urlopen(request)
File "/usr/local/lib/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/local/lib/python2.7/urllib2.py", line 394, in open
response = self._open(req, data)
File "/usr/local/lib/python2.7/urllib2.py", line 412, in _open
'_open', req)
File "/usr/local/lib/python2.7/urllib2.py", line 372, in _call_chain
result = func(*args)
File "/usr/local/lib/python2.7/site-packages/poster-0.8.1-py2.7.egg/poster/streaminghttp.py", line 142, in http_open
File "/usr/local/lib/python2.7/urllib2.py", line 1170, in do_open
r = h.getresponse(buffering=True)
File "/usr/local/lib/python2.7/httplib.py", line 1027, in getresponse
response.begin()
File "/usr/local/lib/python2.7/httplib.py", line 407, in begin
version, status, reason = self._read_status()
File "/usr/local/lib/python2.7/httplib.py", line 371, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ' |
|