我在python中使用urllib2和urllib库
假设我有以下代码
import urllib2
import urllib
url = 'http://ah.example.com'
half_url = u'/servlet/av/jd?ai=782&ji=2624743&sn=I'
req = urllib2.Request(url, half_url.encode('utf-8'))
response = urllib2.urlopen(req)
print response
当我运行上面的代码时,我收到以下错误
Traceback (most recent call last):
File "example.py", line 39, in <module>
response = urllib2.urlopen(req)
File "/usr/lib64/python2.7/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.7/urllib2.py", line 398, in open
response = meth(req, response)
File "/usr/lib64/python2.7/urllib2.py", line 511, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.7/urllib2.py", line 436, in error
return self._call_chain(*args)
File "/usr/lib64/python2.7/urllib2.py", line 370, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 519, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 405: Method Not Allowed
任何人都可以告诉我这里发生的事情以及为什么它不起作用
提前致谢............
答案 0 :(得分:15)
您正在呼叫的服务器告诉您,您尝试呼叫的URL不允许使用POST方法。
通过传递URL的路径部分作为Request
对象数据参数,您将其设为POST而不是GET。
我怀疑您想要发送GET请求:
req = urllib2.Request(url + half_url.encode('utf-8'))
答案 1 :(得分:0)
之所以得到它,是因为Ubuntu Trusty软件包中来自OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\aa\Test.accdb;Jet OLEDB:Database Password=123;");
does not support SSL的Python 3.7。 “解决方案”是降级到Python 3.6。