0

This is my code:

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()

and then an error has occurred:

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

Before I upload the file , I have to login.

so I user cookie.

some code is omitted.

that doesn't matter.

Berkhoff
  • 1
  • 2

1 Answers1

0

I'm guessing you're trying to do a POST request. For that you will need to set get_method appropriately. Simply set:

reqIdea.get_method = lambda: "POST"

I'd also suggest you use a nicer third-party library for these kind of things. (such as requests)

Alexandru Chirila
  • 2,274
  • 5
  • 29
  • 40