Python Requests Throwing SSL Error - python

I am running a Python script in 2 environment using Requests Package.
The Script is working fine in one Environment where,
RedHat version is : Red Hat Enterprise Linux Server release 6.5 (Santiago)
OpenSSL version is : OpenSSL 1.0.1e-fips 11 Feb 2013
Python Version is : Python 2.6.6 (r266:84292, Sep 4 2013, 07:46:00)
Requests Package is : requests-2.7.0-py2.6
But The Same Script is throwing the SSL Error in another Environment where,
RedHat version is : Red Hat Enterprise Linux Server release 6.5 (Santiago)
OpenSSL version is : OpenSSL 1.0.1e-fips 11 Feb 2013
Python Version is : Python 2.6.6 (r266:84292, Sep 4 2013, 07:46:00)
Requests Package is : requests-2.7.0-py2.6
Error is:
raise SSLError(e, request=request)
requests.exceptions.SSLError: [Errno 1] _ssl.c:492: error:100AE081:elliptic curve routines:EC_GROUP_new_by_curve_name:unknown group
I am calling the URL as below
requests.request('GET', url, verify=False, headers = headers)
Can anyone please help me in resolving the above error

you can try updating your openSSL package. The issue is with compatibility of the package with linux . You might get further help by referring to the link:- https://bugzilla.redhat.com/show_bug.cgi?id=1023331

You need to update your system to get a newer version of the OpenSSL package.
Even if openssl version reports the same version 1.0.1e-fips the OpenSSL libraries on both systems differ probably because RedHat added patches. It is common to not upgrade to a newer OpenSSL version if patches are needed but instead apply the patch to the current version to keep compatibility for existing applications.
If you check the version of the rpm package with rpm -qi you will notice that the package version differs on both machines so an upgrade should fix the issue for you.

Related

I can't setup Python

My computer Windows 7 (64-bit)...One or more issues caused the setup to fail. Please fix the issues and then retry setup. For more inforation see the log file. At least Windows 8.1 or Windows Server 2012 are required to install Python 3.10.1 (64-bit)
At least Windows 8.1 or Windows Server 2012 are required to install Python 3.10.1 (64-bit)
You are running Windows 7, you need Windows 8.1, Windows Server 2012 or higher to run Python 3.10.1.
You can:
Install a newer operating system like Windows 10/11.
Install an earlier Python version, I would recommend version 3.8 as that is the latest version that can run on Windows 7 according to the Windows download page.

How to install openssl 1.1.1 for python 2.7?

I installed python 2.7.17 on a windows 10 machine. I then wanted to test its openssl version by running the following inside python:
import ssl
print ssl.OPENSSL_VERSION_INFO
I am getting (1, 0, 2, 20, 15)
I wanted to upgrade to version 1.1.1.
Doing pip freeze I get:
cffi==1.14.0
cryptography==2.8
enum34==1.1.6
ipaddress==1.0.23
pycparser==2.19
pyOpenSSL==19.1.0
six==1.14.0
These seem to be the latest in pip for pyOpenSSL and cryptography.
The openssl I have installed (as part of git bash) is 1.1.1, however, this is not the same version used inside python.
How do I upgrade the version of openssl included in python to 1.1.1 or greater?
EDIT:
In response to the comments, following is a result of python -m OpenSSL.debug:
C:\Users\assaf>python -m OpenSSL.debug
pyOpenSSL: 19.1.0
cryptography: 2.8
cffi: 1.14.0
cryptography's compiled against OpenSSL: OpenSSL 1.1.1d 10 Sep 2019
cryptography's linked OpenSSL: OpenSSL 1.1.1d 10 Sep 2019
Pythons's OpenSSL: OpenSSL 1.0.2t 10 Sep 2019
Python executable: C:\Python27\python.exe
Python version: 2.7.17 (v2.7.17:c2f86d86e6, Oct 19 2019, 21:01:17) [MSC v.1500 64 bit (AMD64)]
Platform: win32
sys.path: ['', 'C:\\WINDOWS\\SYSTEM32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']
As stated above, cryptography and pyOpenSSL are the latest in pip.
The only way to get Python 2.7 to use the current OpenSSL 1.1.1d version for its ssl module is to rebuild it with that version of OpenSSL. For *nix platforms, this is not too hard; it only involves adjusting some initial configuration files. A quick test on macOS showed that the Python 2.7 source code was actually compatible with the OpenSSL 1.1.1d API so that looked promising.
For Windows however, rebuilding Python 2.7 with OpenSSL 1.1.1d is harder. This is because the build system, which relies on Microsoft's msbuild, is not as easy to adjust as the make-based build system on *nix. You can see the associated Visual Studio solution, projects and property files in Python's PCbuild subdirectory.
Additionally, the differences between the OpenSSL 1.0.2 and 1.1.1 versions is slightly larger on Windows, because library names have changed as well, whereas they have stayed the same for the *nix version.
The required modifications to Python's build system for Windows are not too extensive though. It looks like I was able to achieve what you are looking for, after making the change explained at the bottom of this answer. The actual build can be done with the following command run from Python's PCbuild subdirectory:
> build --no-tkinter --no-bsddb -e "/p:PlatformToolset=v141"
for a 32-bits build, or
> build --no-tkinter --no-bsddb -e -p x64 "/p:PlatformToolset=v141"
for a 64-bits build. The --no- options are used to speed up the process and focus on the OpenSSL aspect. v141 stands for Visual Studio 2017, you need to be in a Visual Studio shell for this to work. After that, the following reproduced your test showing the use of OpenSSL 1.1.1d with Python 2.7.17:
> win32\python.exe
Python 2.7.17 (tags/v2.7.17-dirty:c2f86d86e6, Feb 20 2020, 01:04:36) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> print ssl.OPENSSL_VERSION
OpenSSL 1.1.1d 10 Sep 2019
I did not do any testing beyond this.
In summary, the changes to achieve this include
Removed the libeay project from the solution. This was used to build OpenSSL 1.0.2 from source but it is not compatible with OpenSSL 1.1.1. Instead, the solution now relies on the prebuilt OpenSSL 1.1.1d binaries as provided by the Python repo in cpython-bin-deps. Rebuilding OpenSSL yourself as part of the build process is possible but requires more modifications.
Modified the get_externals.bat batch script to download the OpenSSL 1.1.1d prebuilt libraries from the aforementioned cpython-bin-deps repository.
Modified the openssl.props property file that configures several of the _ssl and _hashlib project settings, and made some changes to those projects themselves as well. The adjustments mostly taken from the v3.8.1 release of Python, to link with the new OpenSSL libraries and set the include paths correctly. With this modification, OpenSSL is no longer statically linked as it used to be in 2.7.17, but dynamically linked.
Applied patches to the files Modules/posixmodule.c and Modules/timemodule.c similar to this patch, to allow for building with Visual Studio 2017 -- the same version the prebuilt OpenSSL binaries are created with.
By the way, more stuff than needed gets downloaded in the current build process, including the OpenSSL and nasm source code. This is only to allow for as few modifications to the original build scripts as possible.
If you are interested in the details, you can check out the associated commit in this fork of the cpython repo which I did just for the purpose of clarifying my answer. It is based on the original tag v2.7.17. You should be able to reproduce the build by checking out that branch v2.7.17_ossl_1.1.1 and running the build command in PCbuild as mentioned above. If enough people are interested, I may clean it up and keep it around.

GLIBC 2.14 installation error: forced unwind support is required - RHEL 7.5

I have upgraded my RHEL OS from 6.7 to 7.5. After upgrading, I found some issues when trying to run yum. Below are the details.
# yum repolist
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
/lib64/libc.so.6: version `GLIBC_2.14' not found (required by /lib64/libgcc_s.so.1)
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.6.6 (r266:84292, Aug 9 2016, 06:11:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
After getting this error, I just installed python2.7 and GLIBC 2.14. But when I am trying to install GLIBC 2.14 from my current GLIBC version 2.12, it is throwing some error. Below are the steps that I am using to install GLIBC 2.14:
tar xvfz glibc-2.14.tar.gz
cd glibc-2.14
mkdir build
cd build
../configure --prefix=/opt/glibc-2.14
make
sudo make install
export LD_LIBRARY_PATH=/opt/glibc-2.14/lib:$LD_LIBRARY_PATH
In step5, I am getting error. Below are the details:
# ../configure --prefix=/opt/glibc-2.14
checking for forced unwind support... no
configure: error: forced unwind support is required
I am unaware of this error "unwind support is required".Please let me know how to setup/install forced unwind in Redhat 7.5.
add libc_cv_forced_unwind=yes when configure:
../configure --prefix=/opt/glibc-2.14 libc_cv_forced_unwind=yes
and make

python - how to downgrade openssl

Im having issues with some older certs that are self generated by my routers. I believe it is because openssl no longer supports 3des encryption.
I would like to downgrade my ssl version in python to see if the problems go away.
Current Version:
>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 1.0.1t 3 May 2016'
>>>
I am using the docker image for python. and that runs:
# cat /etc/issue
Debian GNU/Linux 8 \n \l
Im not sure which version 3des was removed in, but I would need to use the version before that I think.
I'm using aiohttp which I believe uses urllib3 for requests and I haven't been able to get past the handshake failure currently, which I believe is because of 3des encryption?
Figure out the version of OpenSSL you want. Taking the example of version 1.0.0, use the following command:
sudo pip install 'pyOpenSSL==21.0.0' --force-reinstall
Full list of old pyOpenSSL released versions: https://pypi.org/project/pyOpenSSL/

Installing python-ldap in a virtualenv on Windows

I'm working on a Django project that is using an ldap authentication module. This is working on our server but I am running into issues getting this running on my windows dev machine.
My environment is using virtualevn and when trying to install pip python-ldap I receive the following message:
error: Unable to find vcvarsall.bat
Does anyone have any idea what could be going wrong?
To expand on #Brandon's answer, to install using the pre-built wheel:
Ensure you have pip 19.2+ installed:
$ pip --version
pip 19.2.3
Check your Python version and architecture (32/64 bit) https://stackoverflow.com/a/10966396/1026:
$ python -c 'import sys; print(sys.version)'
3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
Download the matching pre-built *.whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap
For example given the above Python I picked "python_ldap‑3.2.0‑cp37‑cp37m‑win_amd64.whl"
Install it with:
pip install path\to\your.whl
Unfortunately, many Python modules have trouble installing on Windows. The error you're receiving is one that I was never able to get fixed, even given the vast amount of information available on the web. Give this link a try for a pre-compiled version: http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap

Categories