为什么我不能将方法更改为 PUT。我可以在没有太多代码更改的情况下更改为 PUT 吗?
这是我的代码:
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
#code to change method to PUT
opener.get_method = lambda: 'PUT'
print "now using method:", meth # prints now using PUT
try:
r = opener.open("http://the_url")
except urllib2.HTTPError as e:
if hasattr(e, 'code'):
report += "HTTP error status " + str(e.code) + " FAIL\n"
if hasattr(e, 'reason'):
print "HTTP Error reason " + e.reason
else:
report += "HTTP error occurred FAIL\n"
但我收到运行时错误 HTTP 错误原因 请求方法 'POST' 不支持 PUT 会话测试 HTTP 错误状态 405 FAIL