您的位置:首页 > 理论基础 > 计算机网络

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

2014-10-04 15:03 1796 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐