Redis reports an error when integrating springsecurity: could not read JSON: unrecognized field “enabled”“

When springboot integrates springsecurity, an error occurs:

  By viewing the error reporting information, it is found that the errors are reported where redis is used. In the project, redis is used as a cache to store user information. Everything is normal when spring security is not integrated, but there is a problem after the integration. I checked several blogs on the Internet and found that there is a problem when redis serializes and stores user objects.

Key error messages:

Could not read JSON: Unrecognized field "enabled" (class com.xyc.community.entity.User), not marked as ignorable (11 known properties: "authorities", "status", "activationCode", "username", "createTime", "type", "id", "email", "headerUrl", "salt", "password"])
 at [Source: (byte[])"{"@class":"com.xyc.community.entity.User","id":134,"username":"www","password":"3d3aeebb9cd302ae581dfa8fedd86ceb","salt":"dfc00","email":"[email protected]","type":0,"status":1,"activationCode":null,"headerUrl":"http://images.nowcoder.com/head/134t.png","createTime":["java.util.Date",1555668837000],"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true}"; line: 1, column: 318] (through reference chain: com.xyc.community.entity.User["enabled"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "enabled" (class com.xyc.community.entity.User), not marked as ignorable (11 known properties: "authorities", "status", "activationCode", "username", "createTime", "type", "id", "email", "headerUrl", "salt", "password"])
 at [Source: (byte[])"{"@class":"com.xyc.community.entity.User","id":134,"username":"www","password":"3d3aeebb9cd302ae581dfa8fedd86ceb","salt":"dfc00","email":"[email protected]","type":0,"status":1,"activationCode":null,"headerUrl":"http://images.nowcoder.com/head/134t.png","createTime":["java.util.Date",1555668837000],"enabled":true,"accountNonExpired":true,"accountNonLocked":true,"credentialsNonExpired":true}"; line: 1, column: 318] (through reference chain: com.xyc.community.entity.User["enabled"])

You can see that several fields are added during serialization because the userdetails interface is implemented in the user class in order to integrate springsecurity. These methods have been rewritten

  terms of settlement:

Using the @ jsonignoreproperties annotation, you can ignore these fields when the user object is serialized

Add before user class:

@JsonIgnoreProperties({"enabled","accountNonExpired", "accountNonLocked", "credentialsNonExpired", "authorities"})

Template argument deduction/substitution failed: couldn‘t deduce template parameter [How to Solve]

Article catalog

Error code error reason solution

Error code

We want to implement a generic function to find the maximum value of the interval. The parameters are left and right iterators, which return the maximum value.

#include<iostream>
#include<vector>
using namespace std;
template<class T>
T findmax(typename vector<T>::iterator left,typename vector<T>::iterator right){
    T ret = *left;
    for (;left!=right;++left){
        ret = (*left)>ret ?*left : ret;     
    }
    return ret;
}

int main(){
    vector<int> a({3,4,6,2,1,5});
    cout << findmax(a.begin(),a.end());
    return 0;
}

error:
15:38: error: no matching function for call to ‘findmax(std::vector::iterator, std::vector::iterator)’
15 | cout << findmax(a.begin(),a.end());
5:3: note: candidate: ‘template T findmax(typename std::vector::iterator, typename std::vector::iterator)’
5 | T findmax(typename vector::iterator left,typename vector::iterator right){
5:3: note: template argument deduction/substitution failed:
15:38: note: couldn’t deduce template parameter ‘T’
15 | cout << findmax(a.begin(),a.end());

The reason
The compiler cannot guess that the template T is int based on the type vector< int >::iterator passed in

Solution
Specify the template manually at the place where the function is called.
Replace the used findmax with findmax< int >:

#include<iostream>
#include<vector>
using namespace std;
template<class T>
T findmax(typename vector<T>::iterator left,typename vector<T>::iterator right){
    T ret = *left;
    for (;left!=right;++left){
        ret = (*left)>ret ?*left : ret;     
    }
    return ret;
}

int main(){
    vector<int> a({3,4,6,2,1,5});
    cout << findmax<int>(a.begin(),a.end());
    return 0;
}

Run successfully

Linux accesses the shared directory of windows, pysmb (parameter remote)_Name (defined)

Scheme I

net use this command is only available under windows.

Scheme II

sudo mount -t cifs -o username=administrator,password=password //remote_ share_ server_ ip/share_ Dir./data
this command must use root permission. It cannot be implemented for applications that cannot use root permission. If there is no sudo, an error will be reported:
mount: only root can use "-- options" option

Programme III

Python package pysmb

def check_unc_source(self, unc_path, username, password):
    conn = SMBConnection(username, password, '', remote_name, is_direct_tcp=True)
    result = conn.connect('remote_share_server_ip', 445)
    with open("local_file", "wb") as local_file:
        conn.retrieveFile("share_dir", "file", local_file)

The 4th parameter of SMBConnection, remote_name:

The NetBIOS machine name of the remote server.
On windows, you can find out the machine name by right-clicking on the “My Computer” and selecting “Properties”.
This parameter must be the same as what has been configured on the remote server, or else the connection will be rejected.

You can actually fill in the IP address of the server where the Windows remote shared directory is located, i.e. the same as the first parameter remote_share_server_ip of conn.connect, if it is empty, an error will be reported:
smb.smb_structs.OperationFailure: Failed to retrieve [file] on share_dir: Unable to connect to shared device

[Solved] Original error was: No module named ‘numpy.core._multiarray_umath‘

Original error was: No module named ‘numpy.core._ multiarray_ umath’

Problem description analysis and solution

Problem description

Numpy is clearly installed and frequently used without errors, but the following errors occur:
no module named 'numpy.core_ multiarray_ umath

Analyze problems

    1. the model was not saved successfully due to an error in saving the model. At this time, delete the saved model, and the numpy version is too low </ OL>

 

Solution:

Display version PIP show numpy

Upgrade version PIP install -- upgrade numpy

Solve the problem by uninstalling and reloading:

pip uninstall numpy
 
pip install --upgrade numpy
#or
pip  install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

Cocos creator 2.4.5 2D RPG (Infinite scrolling background implementation)

main points:

By default, the scene comes with a camera to render all objects in the scene. The camera node can be regarded as an empty node, and a camera component is attached under it, so it is invisible. Each scene can have multiple cameras. The rendering levels of multiple cameras are grouped and rendered by associating group names. The rendering levels of multiple cameras comply with the node tree rules. First, the priority is divided according to the level of the camera node, and the lower camera, Its associated group is rendered later; For nodes under the same camera group, the lower the node, the later the rendering. The more you render, the closer the node looks to the top.

case

Camera practice: implementation of infinite parallax rolling map

1、 Camera group rendering

In the menu of Cocos creator, ` item ‘- & gt` Project settings ` – & gt` Changing or adding a group in group management is the same setting as the group management of physical collision.

Add multiple cameras in the scene, then add multiple groups in group management, and then set the settings of the camera   cullingMask   Attribute is the corresponding group. Each camera rendered object is filtered through this cullingmask.

The steps are as follows:

1. Create a camera node. Create an empty node in the hierarchy manager and add a camera component on this node, so that a camera node can be created. According to this method, two camera nodes, farcamera and nearcamera, are added to render the foreground and close-up respectively.

Empty node

Add camera

2. Group management. Add two groups in group management, nearbg and farbg.

Add group

3. Add close view and long view nodes and set group names respectively

prospect

Close range

4. Set the cullmask property of camera, farcamera to farbg and nearcamera to nearbg.

Perspective camera

Close range camera

Here, the multi camera and group rendering settings are completed, and the interface can be seen by running the simulator.

Operation results

2、 Parallax principle

There are two ways of parallax background. The traditional way is to keep the observation point unchanged, move the close view and long-range map, control the speed of close view and long-range map to produce parallax, and form an infinite rolling parallax background.

But what we are talking about here is the opposite process. The background picture is fixed and the observation point (camera) is moved. Due to the relativity of motion, the background picture moves in the opposite direction.

Principle I

As shown in the figure, if the camera keeps moving, it will soon exceed the visual boundary of farbg1. Therefore, two background images should be made. When moving to the boundary of farbg1, put another same background next to the boundary of farbg1. In this way, continuously set the position of farbg alternately, and you can scroll infinitely.

Principle I

The same principle sets the close range. The moving speed of the background is equal to the moving speed of the camera, and the direction is opposite. If the moving speed of the two cameras is different, an infinite rolling parallax background is formed.

3、 Jingjing

Some elements do not move. We call them static scenes, such as the sun and the moon. How to achieve them?

It’s actually very simple. Just use a camera to render them without moving the camera.

Implementation method: add a group celestial, turn on maincamera, set cullingmask to celestial, add a sun node, and set the group to celestial.

Also, when you play the characters, you need to set up a camera to render. This will make some special effects of lens, such as camera following, lens zoom, etc. This will be explained in detail in other articles. Please pay attention to the official account.

Implementation method: add a group player in the project settings, add a player node in the scene editor for character running, and set the group as player. A new node named playercamera is added to the scene editor. A camera component is added and cullingmast is set to player.

Playercamera only renders one player node, so you can see that the characters on the interface are running all the time. In fact, the characters are not moving at all, but the camera in the background is moving.

Final effect:

Effect preview

How to Solve Pytorch DataLoader Loading Error: UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xe5 in position 1023

The complete error reports are:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_comm.py", line 301, in _on_run
    r = r.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position 1023: unexpected end of data

 

Solution:

This is not to solve the problem of Unicode decodeerror: 'UTF-8' codec can't decode byte 0xe5 in position 1023: unexpected end of data , but to solve the problem that the model cannot be iterated. The method is as follows:

Replace the data source in tensor format with numpy format, then convert it to tensor , and finally put it into dataloader

Unicode decodeerror will still be reported when moving from numpy to tensor, but the loaded data will not be encapsulated in the dataloader, resulting in the stop of the data cycle and the training of the model will not be affected.

Taro Use React Hooks Error: TypeError: Object(…) is not a function

  I stepped on a version of the pit today

In the taro project, you want to use react hooks. The code is as follows. Errors are always reported in the wechat development tool

After looking at the official documents, I found that taro was introduced after version 3.xx   Usestate and so on need to be introduced from the corresponding framework react

The code is modified as follows:

// React Hooks
import { useState, useEffect } from 'react' 
import { View, Text } from '@tarojs/components'
import './index.scss'
function Index() {
    const [userName, setUserName] = useState('Ashely')
    return (
        <View>
            <Text>{userName}</Text>
        </View>
    )
}

export default Index

You can compile normally