安装了 python 的 requests 模块,使用中报错,如下
[root@payun ~]# echo $PYTHONPATH [root@payun ~]# [root@payun ~]# python27 Python 2.7.10 (default, Oct 8 2015, 15:46:46) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/python27/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module> from . import utils File "/usr/local/python27/lib/python2.7/site-packages/requests/utils.py", line 26, in <module> from .compat import parse_http_list as _parse_list_header File "/usr/local/python27/lib/python2.7/site-packages/requests/compat.py", line 7, in <module> from .packages import chardet File "/usr/local/python27/lib/python2.7/site-packages/requests/packages/__init__.py", line 29, in <module> import urllib3 ImportError: No module named urllib3 >>> exit() [root@payun ~]# [root@payun ~]# python34 Python 3.4.3 (default, Oct 8 2015, 15:22:41) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import requests Traceback (most recent call last): File "/usr/local/python34/lib/python3.4/site-packages/requests/packages/__init__.py", line 27, in <module> from . import urllib3 File "/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/__init__.py", line 10, in <module> from .connectionpool import ( File "/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 41, in <module> from .response import HTTPResponse File "/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/response.py", line 2, in <module> import zlib ImportError: No module named 'zlib' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/python34/lib/python3.4/site-packages/requests/__init__.py", line 58, in <module> from . import utils File "/usr/local/python34/lib/python3.4/site-packages/requests/utils.py", line 26, in <module> from .compat import parse_http_list as _parse_list_header File "/usr/local/python34/lib/python3.4/site-packages/requests/compat.py", line 7, in <module> from .packages import chardet File "/usr/local/python34/lib/python3.4/site-packages/requests/packages/__init__.py", line 29, in <module> import urllib3 ImportError: No module named 'urllib3' >>>
yum -y install zlib-devel openssl-devel cd /wls/softwares/Python-2.7.10 ./configure --prefix=/usr/local/python27 make make install
Python 2.7.10 (default, Oct 8 2015, 17:29:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> import requests >>> r = requests.get('https://10.25.7.2') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/python27/lib/python2.7/site-packages/requests/api.py", line 69, in get return request('get', url, params=params, **kwargs) File "/usr/local/python27/lib/python2.7/site-packages/requests/api.py", line 50, in request response = session.request(method=method, url=url, **kwargs) File "/usr/local/python27/lib/python2.7/site-packages/requests/sessions.py", line 471, in request resp = self.send(prep, **send_kwargs) File "/usr/local/python27/lib/python2.7/site-packages/requests/sessions.py", line 579, in send r = adapter.send(request, **kwargs) File "/usr/local/python27/lib/python2.7/site-packages/requests/adapters.py", line 430, in send raise SSLError(e, request=request) requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) >>> >>> r = requests.get('https://10.25.7.2',verify=False) /usr/local/python27/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:789: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning) >>> requests.packages.urllib3.disable_warnings() >>> r = requests.get('https://10.25.7.2',verify=False) >>> r.status_code 200 >>>
yum -y install zlib-devel openssl-devel cd /wls/softwares/Python-3.4.3 ./configure --prefix=/usr/local/python34 make make install
Python 3.4.3 (default, Oct 8 2015, 17:58:21) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> import requests >>> r = requests.get('https://10.25.7.2',verify=False) /usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py:789: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning) >>> requests.packages.urllib3.disable_warnings() >>> r = requests.get('https://10.25.7.2',verify=False) >>> r.status_code 200 >>>