Python certification error - Certificate.command install not working/ permission denied? - python

I am working on a developed segment of code that links back up to an existing website to cross ref multiple images - the issue I am encountering seems simple enough but now I feel that I went down a rabbit hole.
I should be able to run this code on my Mac but get the error:
urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify
failed: unable to get local issuer certificate (_ssl.c:1076)
Okay simple - I went to applications and tried to run the Install Certificates.command but then get the error:
ERROR: Could not install packages due to an EnvironmentError: [Errno
13] Permission denied:
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/certifi'
Consider using the --user option or check the permissions.
For both Python 3.7 & 3.8
Okay - I then tried pip(pip, pip3, pip3.7, & pip3.8) install on Certi and Certificates which all worked.
But I still get the error when running my code stating that my certification verification failed. I then did the something again this time with --user and still the same result.
Am I missing something to this - I feel very foolish trying to get this to work when it should be pretty simple.
Thanks

after taking some time away I went with sudo - and that was the correct move - should mention I was on work comp hence the issue - used admin rights and got cert verification.

Related

SSL: CERTIFICATE_VERIFY_FAILED in python while installing package [duplicate]

I get the following error when trying to install Punkt for nltk:
nltk.download('punkt')
[nltk_data] Error loading Punkt: <urlopen error [SSL:
[nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed
[nltk_data] (_ssl.c:590)>
False
TLDR: Here is a better solution: https://github.com/gunthercox/ChatterBot/issues/930#issuecomment-322111087
Note that when you run nltk.download(), a window will pop up and let you select which packages to download (Download is not automatically started right away).
To complement the accepted answer, the following is a complete list of directories that will be searched on Mac (not limited to the one mentioned in the accepted answer):
- '/Users/YOUR_USERNAME/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/nltk_data'
- '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/share/nltk_data'
- '/Users/YOUR_USERNAME/YOUR_VIRTUAL_ENV_DIRECTORY/lib/nltk_data'
In case the link above dies, here is the solution pasted in its entirety:
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download()
Run the above code in your favourite Python IDE or via the command line.
This works by disabling SSL check!
import nltk
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
pass
else:
ssl._create_default_https_context = _create_unverified_https_context
nltk.download()
Run the Python interpreter and type the commands:
import nltk
nltk.download()
from here: http://www.nltk.org/data.html
if you get an SSL/Certificate error, run the following command
bash /Applications/Python 3.6/Install Certificates.command
from here: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
Search 'Install Certificates.command' in the finder and open it.
Then do the following steps in the terminal:
python3
import nltk
nltk.download()
The downloader script is broken. As a temporal workaround can manually download the punkt tokenizer from here and then place the unzipped folder in the corresponding location. The default folders for each OS are:
Windows: C:\nltk_data\tokenizers
OSX: /usr/local/share/nltk_data/tokenizers
Unix: /usr/share/nltk_data/tokenizers
This is how I solved it for MAC OS.
Initially after installing nltk, I was getting the SSL error.
Solution:
Goto
cd /Applications/Python\ 3.8
Run the command
./Install\ Certificates.command
Now if you try again, it should work!
Thanks a lot to this article!
You just need to Install the certificate doing this simple step
In the python application folder double-click on the file 'Certificates.command'
this will make a prompt window show in your screen and basically will automatically install the certificate for you, close this window and try again.
My solution is:
Download punkt.zip from here and unzip
Create nltk_data/tokenizers folders under home folder
Put punkt folder under tokenizers folder
There is a very simple way to fix all of this as written in the formal bug report for anyone else coming across this problem recently (e.g. 2019) and using MacOS. From the bug report at https://bugs.python.org/issue28150:
...there is a simple double-clickable or command-line-runnable script ("/Applications/Python 3.6/Install Certificates.command") that does two things: 1. uses pip to install certifi and 2. creates a symlink in the OpenSSL directory to certifi's installed bundle location.
Simply running the "Install Certificates.command" script worked for me on MacOS (10.15 beta as of this writing) and I was off and running.
My solution after nothing worked. I navigated, via the GUI to the Python 3.7 folder, opened the 'Certificates.command' file in terminal and the SSL issue was immediately resolved.
A bit late to the party but I just entered Certificates.command into Spotlight which found it and ran it. All fixed in seconds.
I'm running mac Catalina and using python 3.7 installed by Homebrew
It means that you are not using HTTPS to work consistently with other run time dependencies for Python etc.
If you are using Linux (Ubuntu)
~$ sudo apt-get install ca-certificates
Should solve the issue.
If you are using this in a script with a docker file, you have to make sure you have install the the ca-certificates modules in your docker file.
For mac users,
just copy paste the following in the terminal:
/Applications/Python\ 3.10/Install\ Certificates.command ; exit;
First go to the path /Applications/Python 3.6/ and run
Install Certificates.command
You will admin rights for the same.
If you are unable to download it, then as other answer suggest you can download directly and place it. You need to place them in the following directory structure.
> nltk_data
> corpora
> brown
> conll2000
> movie_reviews
> wordnet
> taggers
> averaged_perceptron_tagger
> tokenizers
> punkt
Updating the python certificates worked for me.
At the top of your script, keep:
import nltk
nltk.download('punkt')
In a separate terminal run (Mac):
bash /Applications/Python <version>/Install Certificates.command
For me, the solution was much simpler: I was still connected to my corporate network/VPN which blocks certain types of downloads. Switching the network made the SSL error disappear.

could not import requests and bs4

I want to import requests library and bs4 in pycharm but I got( no module )
and as i click install package I got error
It recommend to update pip 20 to 21 but when I want to upgrade pip in scripts folder I got invalid syntax error
Based on
certificate verify failed: certificate not yet valid
I'm pretty certain that your computer's clock is incorrect. Check that first. If that's not the case, there might be a broken MITM SSL proxy in the way, which we can't do much about.
As for your problem upgrading Pip, you have a typo. You'll want --upgrade, not -upgrade. However, that's likely to fail too if you can't establish connections to the server hosting Python packages (including Pip).

Error 13 Permission Denied, Pycharm says my SDK seems invalid

I am downloading an old school project in preparation for a job interview and I am trying to run it on PyCharm. I originally used an environment of Python 2.7 and although I do still have 2.7 installed I am running Python 3 on current projects.
When I try to open the project, I am getting an alert saying I need to set my configuration. When I tried to add an interpreter, it tells me that my SDK seems invalid and gives me error 13 (permissions denied).
I have tried following the solution suggested here (PyCharm error: [Errno 13] Permission denied)
to fix the root permissions, and that didn't work. I uninstalled Python 2.7 and tried to remove any references to it, but that hasn't worked either. I am so incredibly confused, any help in the right direction would be very appreciated.

How to get pip proxy to work with company certificate-chain?

I am trying to get pip to work behind my work's proxy network. I have the credentials for the proxy and I have the certificate-chain files, but no matter what I do I cannot get it to stop throwing an SSL error:
Could not fetch URL https://pypi.python.org/simple/pyinstaller/: There was a problem confirming the
ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645) - skipping
I've seen that pip.ini is supposed to exist in %APPDATA% but it isn't present, not even a pip folder exists there. Furthermore, people who were missing the file were able to create it and have it work that way. I tried this too and it did not work for me. I have even tried specifically specifying the cert in the pip install statement itself with --cert but with no luck.
What do I need to do?
The certificates should live in Lib\site-packages\pip\_vendor\certifi\cacert.pem relative to your Python install directory. For example, if you have installed Python in C:\Python3, then the list of certificates is found in C:\Python3\Lib\site-packages\pip\_vendor\certifi\cacert.pem. If you are using a python virtual environment, it is located within the venv.
You need to append your company certifcate to this cacerm.pem file. Make sure that the company certificate is base-64 encoded (sometimes also referred to as PEM format). Then you can use a text editor to concatenate the files.
Note: If you upgrade pip, your changes to cacert.pem will likely be lost. So, be prepared to repeat this operation after each update of pip.

Python Speedtest facing problems with certification _ssl.c:1056

I am trying to use the following code, on Speedtest API
def get_bytes(self):
s = speedtest.Speedtest()
s.get_best_server()
s.download()
s.upload()
res = s.results.dict()
print(res["download"], res["upload"], res["ping"])
However I am facing some problems with this connection. All the times I am receiving this error.
speedtest.ConfigRetrievalError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>
I am using Python 3.7 on a MacOS Mojave and already tried to update the certifi on virtualenv
Do you have any idea?
I guys, finally I found the error.
In this case, you need to install the certifications on your machines.
The certification are:
MacintoshHD > Applications > Python 3.7 > Install Certificates.command
Double click on certifications and its going to work this solution.
Homebrew's speedtest-cli seems to use Python 2.7. I could not figure out how to fix the certificates, but found this workaround:
$ python3 /usr/local/bin/speedtest

Categories