这是我的代码:
user_agent = *Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)*
#######cookie
opener = poster.streaminghttp.register_openers()
opener.add_handler(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
params={*zipFile*:open("123456.zip","rb"),"projectName":"test"}
datagen, headers = poster.encode.multipart_encode(params)
reqIdea = urllib2.Request("http://biqatest.baidu.com/dispatch/project/upload", datagen, headers)
reqIdea.add_header(*User-Agent*,user_agent)
print urllib2.urlopen(reqIdea).read()
然后发生错误:
File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 405: Method Not Allowed
在我上传文件之前,我必须登录。
所以我使用cookie。
省略了一些代码。
没关系。