Tag Archives: python

Sslcertverificationerror when downloading using Python: [SSL: certificate_verify_failed] error

When downloading the dataset on the pytorch official website, an error is reported in sslcertverificationerror: [SSL: certificate_verify_failed]. The following is my solution.

Error reason: when opening HTTPS link with urllib, SSL certificate will be checked once. When the target website uses a self signed certificate, it will throw the error of urlib2.urlerror.

Solution: cancel certificate validation globally
Import SSL
SSL_ create_ default_ https_ context = ssl._ create_ unverified_ context

Reference article link: https://blog.csdn.net/yixieling4397/article/details/79861379

Solving environment: failed solution to the problem encountered when updating Anaconda

Problem:
in the problem of handling Anaconda’s Navigator
involves upgrading the navigator
command: CONDA update Anaconda navigator

solution:
Add Anaconda Python free warehouse:

conda config –add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  conda config –set show_ channel_ URLs yes
then upgrade again. (the first one already exists and will be prompted.)

ERROR: Failed building wheel for mujoco-py [How to Solve]

This error occurred in the last step of installing mujoco.

All the previous steps have been obtained, including downloading mjkey, installing VC + + buildtools, downloading mjpro150 and the corresponding version of mujoco py. In many tutorials, it is mentioned that PIP install mujoco py = = 1.50.1.68 should be run at last, so an error appears in the title.

function

pip install -e <path>

< path> Is the local mujoco py file directory. The installation was successful.

Attached:

During the first import, the compilation will be performed first, and errors may be reported, such as mujoco and mujoco_Py installed pit code farm home

SparkException: Python worker failed to connect back

Error reporting: org.apache.spark.sparkexception: Python worker failed to connect back

Org.apache.spark.sparkexception: Python worker failed to connect back
tried various online methods, and then
solution:
put my computer – Management – advanced system settings – environment variables – system variables,
put spark_ Set home to the EXE file of python, as shown in the following figure:

it’s done
WIN10 Spark 3.1.2

Failed to import module __PyInstaller_hooks_0_IPython required by hook for module

Failed to import module __ PyInstaller_ hooks_ 0_ IPython required by hook for module problem solving

Method 1 and method 2

Method 1

It may be a problem with pyinstaller. Try reinstalling pyinstaller
enter in the command line:

>>> pip uninstall pyinstaller
>>> pip install pyinstaller

Method 2

The error can be caused by the installation of outdated IPython in the environment. We can try to update it to a newer version
enter in the command line:

>>> pip install --upgrade IPython

I hope I can help you!

Normalize error: TypeError: Input tensor should be a float tensor…

The following error is reported when using tensor ` normalization

from torchvision import transforms
import numpy as np
import torchvision
import torch

data = np.random.randint(0, 255, size=12)
img = data.reshape(2,2,3)


print(img)
print("*"*100)
transform1 = transforms.Compose([
    transforms.ToTensor(), # range [0, 255] -> [0.0,1.0]
    transforms.Normalize(mean = (10,10,10), std = (1,1,1)),
    ]
)
# img = img.astype('float')
norm_img = transform1(img) 
print(norm_img)

You can add this sentence. In fact, it is to set the element type. See the tips above

Python Error: certificate verify failed: certificate has expired

Let’s talk about the situation at that time. Because there is no cifar10 data set on this machine, when downloading cifar10 with the following code:

trainset = torchvision.datasets.CIFAR10(root='./data', train=True,
                                        download=True, transform=transform)

Certificate verify failed: the error message certificate has expired appears.

Later, I found that the following two lines can be added to the file header:

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

Done! happy

Object of type timestamp is not JSON serializable

First of all, the reason for the error is the datetime type field when exporting JSON.

Added in the code:
class dateencoder (JSON. Jsoneencoder):
Default (self, obj):
if isinstance (obj, datetime. Datetime):
return obj.strftime (“% Y -% m -% DT% H:% m:% s”)
else:
return json.jsoneencoder.default (self, obj)

Then add a CLS = dateencoder
in json.dump to solve the problem

As shown in the figure:


no error will be reported

Error no module named ‘in newly installed Python_ sqlite3‘

Tencent cloud server Ubuntu 20 already has Python 3.8. Download the installation package from Huawei cloud. After installing Python 3.9, an error is reported

solve:

Copy the dependent files from the existing 3.8 to 3.9, and then rename them. The command is as follows

ubuntu@esoaru-net ~/github/aiopathlib
☺  python3.8 -c 'import _sqlite3;print(_sqlite3.__file__)'                                                                                                          master ✗
/usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so
ubuntu@esoaru-net ~/github/aiopathlib
☺  which python3.9                                                                                                                                                  master ✗
/usr/local/bin/python3.9
ubuntu@esoaru-net ~/github/aiopathlib
☺  cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /usr/lib/python3.9/lib-dynload/                                                        master ✗
cp: cannot create regular file '/usr/lib/python3.9/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so': Permission denied
ubuntu@esoaru-net ~/github/aiopathlib
☹  sudo cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /usr/lib/python3.9/lib-dynload/                                                   master ✗
ubuntu@esoaru-net ~/github/aiopathlib
☺  python3.9 -c 'import _sqlite3;print(_sqlite3.__file__)'                                                                                                          master ✗
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named '_sqlite3'
ubuntu@esoaru-net ~/github/aiopathlib
☹  cd /usr/lib/python3.9/lib-dynload                                                                                                                                master ✗
ubuntu@esoaru-net /usr/lib/python3.9/lib-dynload
☺  sudo mv _sqlite3.cpython-38-x86_64-linux-gnu.so _sqlite3.cpython-39-x86_64-linux-gnu.so
ubuntu@esoaru-net /usr/lib/python3.9/lib-dynload
☺  python3.9 -c 'import _sqlite3;print(_sqlite3.__file__)'
/usr/lib/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so
☹  sudo cp /usr/lib/python3.9/lib-dynload/* /usr/local/lib/python3.9/lib-dynload/  

Summary:

It’s actually a line of command

sudo cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so /usr/lib/python3.9/lib-dynload/_sqlite3.cpython-39-x86_64-linux-gnu.so

Pandas uses str.contains to filter error [How to Solve]

When using pandas to filter excel,

df.loc[df['threat_type'].str.contains("DGA")]

The following error messages appear:

ValueError: Cannot mask with non-boolean array containing NA/NaN values

It is reported that the grouping column contains non-string contents. Because the use of .Str.contains requires that the field must be a string and cannot have numbers,
so it is added to the code

df.loc[df['threat_type'].str.contains("DGA", na=False)]

This enables the function to directly ignore non-string situations.