urllib2.HTTPError: HTTP Error 405(Method Not Allowed)

http server端要求GET方法,而请求的时候却使用了POST方法,因此出现了405错误

urllib2-GET方法

import urllib2,urllib,sys
url = "http://www.abc.com"
info = [('user','python'),('pass','python')]
getURL = url + "?" + urllib.urlencode(info)
request = urllib2.Request(getURL)
response = urllib2.urlopen(request)

>>> url="http://www.abc.com"
>>> search = [('user','python'),('pass','python')]
>>> getURL = url + "?" + urllib.urlencode(search)
>>> print getURL
http://www.abc.com?user=python&pass=python

urllib2-POST方法

url = "http://www.abc.com"
info = urllib.urlencode([('q','python')])
request = urllib2.Request(url,info)
response= urllib2.urlopen(request)




你可能感兴趣的:(urllib2.HTTPError: HTTP Error 405(Method Not Allowed))