Category Archives: Error

Importerror: no module named * [How to Solve]

1. Question

After switching the project from pycharm to sublime text, it is found that a * Py file, the module cannot be found.

2. Cause

When you start the interpreter in the IDE, the current working directory is the project directory, which can successfully call the modules in the same project; However, when you start from the command line, the current working directory is the directory where you started the interpreter. If the current location is not the project directory, the modules in the project directory will not be found. Therefore, an error is reported when running: modulenotfounderror: no module named

3.Solution

Method 1: put the module path into the environment variable as a global variable

Method 2: Add sys.path.append (project directory) at the beginning of the running file

[Solved] Spring MVC cross server upload error: returned a response status of 405 method not allowed

The error of uploading picture newspaper 405 across servers is because Tomcat is read-only by default. We turn off read-only and allow adding files instead.

Solution: Find the web.xml file in the tomcat installation directory, open it and add the following code in the servlet:

<!– Allow Tomcat server to add files — >

< init-param>
< param-name> readonly
< param-value> false

How to Solve Error in redis insertion list

When the position of the class changes or other effects change the serialization ID, the previously serialized list cannot be deserialized. Instead of resetting the list, setlist adds the list later.

When the following code cannot be serialized, it will always set the list, which will cause the list to be too large. When you request the list again, it will report that redis cannot be connected

report errors

Solution:

Replace with string, and check whether there is the use of redis’s setlist when changing the location of the class

[Solved] Mybatis error: attempted to return null from a method with a primitive return type (int)

1. Origin of the problem

When viewing the log, I found that a line of error message was printed in the log:

The data of assembled pets that have been released is abnormal — & gt; Mapper method ‘applets. user. mapper. xxxMapper. xxxmyRank attempted to return null from a method with a primitive return type (int).

The meaning is well understood. The query method of xxxmyrank in a mapper file returns null, but it needs to return an int type number, so an error is reported.

2. Problem analysis

Fdafdsaf query is a simple query used to query a ranking. If you query the ranking yourself, you can use int type to receive it. At the beginning of the test, there was no problem, but after the project was really launched

Report this problem before you know that this problem exists in the previously written code. The reason for this problem is that the database does not query the corresponding data, so it returns a null value. When you write your own code, you use the int type receive. As shown in the figure below:

3. Solution

After finding the cause of the problem, it is easy to solve it. Change the received int type to the wrapper type integer type class for reception, so as to solve this problem. Because the integer type can be null, regardless of the specific value returned

Or a null value, can receive. Then, you can process the null value in the code, and the problem is solved.

Expansion: this method is mainly used in query. When writing custom numeric fields in Java code, it is best to use the wrapper type to receive them,

Byte,Boolean,Short ,Character,Integer,Long,Float,Double.

The principle is the same. If you query the entity class or use the entity class to accept the value passed by the front end, there may be no value null. At this time, using the wrapper type can solve this problem.

Go executable file error: sh:/ xxx: not found [How to Solve]

background

An error is reported when an executable file packaged by a project is executed in the alpine container

Solution:

It is judged that the lack of dependent environment leads to the unrecognization of this executable file. Install glibc to solve the problem

You can also directly change the from image to busybox: glibc

cat Dockerfile 
FROM alpine:3.14
COPY xxx /tmp/
ARG TZ="Asia/Shanghai"
ENV TZ ${TZ}
RUN  mkdir -p /opt/xxx && mv /tmp/xxx /tmp/ysera_mgtv.conf  /opt/xxx && \
     chmod 777 /opt/xxx/xxx && \
     sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories  && \
     apk add tzdata && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime  && \
     wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
     wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.29-r0/glibc-2.29-r0.apk && \
     apk add glibc-2.29-r0.apk

USER root
CMD ["/opt/xxx/xxx"]

How to Solve Android wireless debug Error

1. Commands for ADB related wireless debugging:

adb tcpip < PORT>

connects Android devices wirelessly through TCPIP. Port is the port number, which can be specified at will (e.g. ADB TCPIP 6666)).

ADB connect
ADB: Usage: ADB connect host [: Port]

after entering ADB connect enter on the command line, the system prompts the usage of the command:
where host is the IP address of the Android device, port is the port number specified when using the ADB TCPIP command, and: connection is used between them (e.g. ADB connect 192.168.1.188:6666).

2. Commands to supplement ADB display/designated devices

ADB devices

View current device

adb -s < device>

it is used to operate the specified equipment we want

3. Specific operation of wireless connection

1. Connect Android device with USB data cable;

2. Enter ADB TCPIP command on the command line (for example: ADB TCPIP 9999);

3. Disconnect the USB data cable (the data cable is disconnected from the device);

4. On the command line, enter ADB connect & lt; host> [:<port>] Command (for example: ADB connect 192.168.1.188:9999)

4. Problems encountered

Open the terminal command window (or terminal in as) and enter the following command:

ADB TCPIP 6666
error: more than one device/emulator

an error is reported here: “error: more than one device/emulator”
then use the following command to view the device

adb devices
List of devices attached
D1CGAP1234506666 device
192.16. 31.55:5555 device

find the device d1cgap1234506666, which is the serial number of the Android mobile phone I need to conduct wireless debugging. 172.16 can be found in its mobile phone status information 31.39 is the IP address of Android phone (the location of checking the IP address of each phone may be different).

Continue using the following command:

adb -s D1CGAP1234506666 tcpip 6666
adb -s D1CGAP1234506666 connect 172.16. 31.39:6666
connected to 172.16. 31.39:6666

connected to host [: Port] indicates that the infinite connection is successful.

[Solved] VS winsock.h and ws2def.h a large number of redefined error

Error reporting reason:

We know that Windows network programming requires at least two header files: winsock2.h and windows.h, and there is an old version of winsock.h before WinSock2.0. It is the order in which these three header files are included that causes the above problems.

The content of winsock2.h has the following macro definitions at the beginning of the file:

#ifndef _WINSOCK2API_
#define _WINSOCK2API_
#define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */

......
...
......

/*
 * Pull in WINDOWS.H if necessary
 */
#ifndef _INC_WINDOWS
#include <windows.h>
#endif /* _INC_WINDOWS */

This is the most common protection measure to prevent repeated inclusion of header files.
The definition of _WINSOCKAPI_ prevents the inclusion of the old file winsock.h, that
is, if the user includes winsock2.h first, then it is not allowed to include winsock.h. The
second half of the effect is: if the user does not include windows.h ( _INC_WINDOWS (defined in windows.h) automatically includes it to define the types and constants required by WinSock2.0.

Now switch to windows.h, we will find the following: (Note: here is the difference between windows.h in MS’s Platform SDK and the file that comes with VC)

#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif

In fact, it is easy to understand that files contain each other, and the definition order leads to the inclusion of Winsock before Winsock 2, which will lead to a large number of repeated definition errors.

Solution:

Find the code that contains windows.h and Winsock2.h, let Winsock2 be included before windows
(or write a header file to solve this problem)

In StdAfx.h add:

#include <WinSock2.h>
#include <windows.h>

It can be solved.

If it is found that the solution does not contain these two files, it is possible that the content is used in the development package or other files.

[Solved] interceptor Cross-Domain Access-Control-Allow-Origin Error

I use vue3 + spring boot, which is developed by front-end and back-end separation technology. For cross-domain problems, I add the following code:

@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedHeaders(CorsConfiguration.ALL)
                .allowedMethods(CorsConfiguration.ALL)
                .allowCredentials(true)
                .maxAge(3600); // No further pre-testing required within 1 hour (send OPTIONS request)
    }

}

The above code is useless, and then it is used in the interceptor to add the following code:

String origin = request.getHeader("Origin");
response.setHeader("Access-Control-Allow-Origin", origin);

Add to solve the problem.