Python 2.7 and 3.4 requests Error: No module named ‘zlib’

Error reporting

The requests module of Python is installed, and an error is reported during use, as follows
is displayed

[root@payun~]#echo$PYTHONPATH

[root@payun~]#
[root@payun~]#python27
Python2.7.10(default,Oct82015,15:46:46)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
File"/usr/local/python27/lib/python2.7/site-packages/requests/__init__.py",line58,in<module>
from.importutils
File"/usr/local/python27/lib/python2.7/site-packages/requests/utils.py",line26,in<module>
from.compatimportparse_http_listas_parse_list_header
File"/usr/local/python27/lib/python2.7/site-packages/requests/compat.py",line7,in<module>
from.packagesimportchardet
File"/usr/local/python27/lib/python2.7/site-packages/requests/packages/__init__.py",line29,in<module>
importurllib3
ImportError:Nomodulenamedurllib3
>>>exit()
[root@payun~]#


[root@payun~]#python34
Python3.4.3(default,Oct82015,15:22:41)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
Traceback(mostrecentcalllast):
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/__init__.py",line27,in<module>
from.importurllib3
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/__init__.py",line10,in<module>
from.connectionpoolimport(
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py",line41,in<module>
from.responseimportHTTPResponse
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/urllib3/response.py",line2,in<module>
importzlib
ImportError:Nomodulenamed'zlib'

Duringhandlingoftheaboveexception,anotherexceptionoccurred:

Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
File"/usr/local/python34/lib/python3.4/site-packages/requests/__init__.py",line58,in<module>
from.importutils
File"/usr/local/python34/lib/python3.4/site-packages/requests/utils.py",line26,in<module>
from.compatimportparse_http_listas_parse_list_header
File"/usr/local/python34/lib/python3.4/site-packages/requests/compat.py",line7,in<module>
from.packagesimportchardet
File"/usr/local/python34/lib/python3.4/site-packages/requests/packages/__init__.py",line29,in<module>
importurllib3
ImportError:Nomodulenamed'urllib3'
>>>

Python 2.7.10 solution

yum-yinstallzlib-developenssl-devel
cd/wls/softwares/Python-2.7.10
./configure--prefix=/usr/local/python27
make
makeinstall

verification

Python2.7.10(default,Oct82015,17:29:37)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux2
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
>>>r=requests.get('https://10.25.7.2')
Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
File"/usr/local/python27/lib/python2.7/site-packages/requests/api.py",line69,inget
returnrequest('get',url,params=params,**kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/api.py",line50,inrequest
response=session.request(method=method,url=url,**kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/sessions.py",line471,inrequest
resp=self.send(prep,**send_kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/sessions.py",line579,insend
r=adapter.send(request,**kwargs)
File"/usr/local/python27/lib/python2.7/site-packages/requests/adapters.py",line430,insend
raiseSSLError(e,request=request)
requests.exceptions.SSLError:[SSL:CERTIFICATE_VERIFY_FAILED]certificateverifyfailed(_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:UnverifiedHTTPSrequestisbeingmade.Addingcertificateverificationisstronglyadvised.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
>>>

Python 3.4.3 solution

yum-yinstallzlib-developenssl-devel
cd/wls/softwares/Python-3.4.3
./configure--prefix=/usr/local/python34
make
makeinstall

verification

Python3.4.3(default,Oct82015,17:58:21)
[GCC4.4.720120313(RedHat4.4.7-4)]onlinux
Type"help","copyright","credits"or"license"formoreinformation.
>>>
>>>importrequests
>>>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:UnverifiedHTTPSrequestisbeingmade.Addingcertificateverificationisstronglyadvised.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
>>>

 

Similar Posts: