Category Archives: How to Fix

python got an unexpected keyword argument

 
The following exception is simulated:

 

def add(x,y):
   return x+y

print(add(bbb=3))

report errors:

TypeError: add() got an unexpected keyword argument ‘bbb’
 
reason:

The add function has no parameter BBB and passes an unknown parameter BBB

 
resolvent:

def add(x,y,*args,**kwargs):
   return x+y

print(add(bbb=3))

This is not a mistake

def add(**kwargs):
   return 4

print(add(pre=4,bbb=3))

 

The springboot project does not start and has no error messages

Project scenario: the project cannot be started after merging code branches

project scenario: after the code branches are merged, the project cannot be started and no error message is reported

try {
            ConfigurableApplicationContext context = SpringApplication.run(TestApplication.class, args);
            SpringContextUtils.setContext(context);
        }catch (Exception e){
            e.printStackTrace();
        }

Solution:

add try catch to the startup class to catch the exception information, and modify it according to the prompt to save the exception information

When installing mysql, an error occurs when executing the installation command with the CMD window. Install / Remove of the Service denied

This error report means that I don’t have the right to install and delete because I didn’t use my own computer. At the beginning, I didn’t notice the black window. This problem indicates that I don’t have the right to install and delete. Because you are not using your own computer, I didn’t notice that the default identity of Win + R is the current user, not the administrator, so you need to run CMD as an administrator.

Steps: 1. Open my computer, and the cmd.exe file is located on Disk C — & gt; Window folder — & gt; System32 folder, right-click to run as administrator.

            2. At this time, execute the MySQL – install command again, and the installation is successful.

I have also configured environment variables here, but there is no exception after checking that CMD does not take effect globally. So I add the absolute path of bin folder to path directly. At this time, the MySQL command takes effect globally. If a small partner encounters the same problem, you can try this solution.

 

An error was reported in the process of importing the table from mysql5.7: [err] 1067 – invalid default value for ‘***‘

It is said on the Internet that my.ini or my.cnf files should be changed so that they can be used. I didn’t use them. I used the following method

My problem is that when creating database tables visually, I choose timestamp as the data type and report an error

solution: add current to the default value_ The value of timestamp can be from 10:00:00 on January 1, 1970 to 23:59:59 on December 31, 2037

Git command line configuration and configuration file to solve clone error libressl_ connect: SSL_ ERROR_ SYSCALL in connection to github. com:443

Intro

When clone comes from a GitHub warehouse, an error is reported as follows:

leung@wuyujin coderepo % git clone https://github.com/spring-guides/gs-consuming-web-service.git
Cloning into 'gs-consuming-web-service'...
fatal: unable to access 'https://github.com/spring-guides/gs-consuming-web-service.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 
leung@wuyujin coderepo % git clone https://github.com/spring-guides/gs-consuming-web-service.git
Cloning into 'gs-consuming-web-service'...
fatal: unable to access 'https://github.com/spring-guides/gs-consuming-web-service.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 
leung@wuyujin coderepo % 

Core error: libressl_ connect: SSL_ ERROR_ SYSCALL in connection to github. com:443

It’s about SSL authentication.

to configure

The GIT configuration of the current user will be written in the . Gitconfig configuration file in the current user directory (if there is no new touch ~ /. Gitconfig )
take user wuyujin as an example, the full path of GIT configuration file is:
windows: C:
linux: /home/wuyujin /. Gitconfig
MacBook: /users/wuyujin /. Gitconfig

Git can be configured in two ways:
through the command line setting, the corresponding configuration items will be automatically written to the configuration file (premise: you know how to write the command)
directly modify the configuration file (premise: you know the format/rules of the configuration file)

Command required:

git config --global http.sslVerify false
git config --global https.sslVerify false

The effect is that the configuration file is written as follows:

[http]
        sslVerify = false
[https]
        sslVerify = false

In addition, user. Name user. Email and other parameters can be set (not necessary here).

shell


leung@wuyujin coderepo % git config --global http.sslVerify false
leung@wuyujin coderepo % git config --global https.sslVerify false

leung@wuyujin coderepo % more ~/.gitconfig 

[http]
        sslVerify = false
[https]
        sslVerify = false
leung@wuyujin coderepo % 

Once again, clone, success.

Another possibility

When you clone a warehouse, open a new window clone another window. report errors.

One clone at a time will not report an error.

That is: parallel clone -- & gt; Serial clone

Error in Maven clean or package

1. Run the MVN – V command and report an error. Java.io.filenotfoundexception: F:: (java-maven-apache-maven-3.6.3) bin…/conf/logging

just create a logging folder

2. My java development and learning journey; Java NiO reports java.nio.charset.malformedinputexception: input length = 1 exception
I show that all encoding in idea is set to UTF-8, and check

, but it still can’t
and then read this blog: https://blog.csdn.net/ouyang_ Peng/article/details/46462379
, delete the Chinese garbled code in application.properties and rewrite it in Chinese.

By the way, when using terminal to build MVN package in idea, you can add – x,
that is

mvn package -X

In this way, you can see the specific error log

Tomcat error: 500 The server encountered an internal error that prevented it from fulfilling this request

Background:
I use JDK1.8 and tomcat8.0, but I encounter the following two problems


then I made a new tomcat, and its version is as follows:

and it succeeded…..

The reason: Tomcat version is higher than JDK version

In addition, I have problems with my code
here is the error code:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="computer"%>
<html>
The three values entered a,b,c (representing the three sides of a triangle or the upper base, lower base and height of a trapezoid);
<body color=cyan>
        <form action="" method=get name=form> 
        <%--Get parameters to submit to yourself--%>
        <table>
        <tr><td>Enter value a: </td>
            <td><input type="text" name="a"></td>
        </tr>
        <tr><td>input value b: </td>
            <td><input type="text" name="b"></td>
        </tr>
        <tr><td>input value c: </td>
            <td><input type="text" name="c"></td>
        </tr>
        </table>
        <input type="radio" name="r" value="triangle">stands for triangle
        <input type="radio" name="r" value="lader">stands for trapezoid
        <br>
        <input type="submit" name="submit" value="submit" name=submit>stands for submit button
        </form>
        <% String a=request.getParameter("a");
           String b=request.getParameter("b");
           String c=request.getParameter("c");
           String cd=request.getParameter("r");
           if(a==null||b==null||c==null){
              a="0";
              b="0";
              c="0";
              cd="0";
                      
           }
           if(a.length()>0&&b.length()>0&&c.length()>0){
        %>
           <computer:Getarea numberA="<%=a%>" numberB="<%=b%>"
                             numberC="<%=c%>" condition="<%=cd%>"/>
           
           
           <br><%= message%>
           <br><%= area %>
        
        <% }
        %>
        </body>
        </html>


            
        

The reason for the error is that there are two more spaces. The error report is the same
here is the correct code:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="computer"%>
<html>
The three values entered a,b,c (representing the three sides of a triangle or the upper base, lower base and height of a trapezoid);
<body color=cyan>
        <form action="" method=get name=form> 
        <%--Get parameters to submit to yourself--%>
        <table>
        <tr><td>Enter value a: </td>
            <td><input type="text" name="a"></td>
        </tr>
        <tr><td>input value b: </td>
            <td><input type="text" name="b"></td>
        </tr>
        <tr><td>input value c: </td>
            <td><input type="text" name="c"></td>
        </tr>
        </table>
        <input type="radio" name="r" value="triangle">stands for triangle
        <input type="radio" name="r" value="lader">stands for trapezoid
        <br>
        <input type="submit" name="submit" value="submit" name=submit>stands for submit button
        </form>
        <% String a=request.getParameter("a");
           String b=request.getParameter("b");
           String c=request.getParameter("c");
           String cd=request.getParameter("r");
           if(a==null||b==null||c==null){
              a="0";
              b="0";
              c="0";
              cd="0";
                      
           }
           if(a.length()>0&&b.length()>0&&c.length()>0){
        %>
           <computer:Getarea numberA="<%=a%>" numberB="<%=b%>"
                             numberC="<%=c%>" condition="<%=cd%>"/>
           
           
           <br><%=message%>
           <br><%=area %>
        
        <% }
        %>
        </body>
        </html> 

[Solved] failed to req API:/nacos/v1/ns/instance after all servers

Scenario: CentOS virtual machine SpringCloud-Nacos Dubbo integration error reporting
failed to req API:/nacos/v1/ns/instance after all servers([192.168.56.101:8848, 192.168.56.102:8848, 192.168.56.103:8848]) tried: failed to req API:192.168.56.102:8848/nacos/v1/ns/instance. code:400 msg: <html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id=’created’>Fri May 21 01:29:11 CST 2021</div><div>There was an unexpected error (type=Bad Request, status=400).</div><div>receive invalid redirect request from peer 192.168.56.101</div></body></html>
Cause.
When the nacos service is started, the virtual machine’s enp0s3 NIC is used with an ip of 10.0.2.x
And 192.168.56.x is the address of the enp0s8 NIC
So the solution here is to open the configuration item in /nacos/conf/application.properties and specify the ip on it

Redis: How to Configurate Redis.conf File

The configuration file is case insensitive

Other configuration files can be included

###Network-related###
# bind 127.0.0.1 # Bind the listening NIC IP, comment out or configure to 0.0.0.0 to make any IP accessible

protected-mode yes # Turn off protected mode, use password access

port 6379 # Set the listening port, it is recommended that production environments use custom ports

timeout 30 # how long the client connection is idle before disconnecting, in seconds, 0 means disabled

###General configuration###
daemonize yes # default is no, run in the background as a daemon

pidfile /var/run/redis_6379.pid # If running in the background, specify the pid process file name

### log###
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)
# warning (only very important/critical messages are logged)
loglevel notice

logfile "" # file name of the log

databases 16 # number of databases default is 16 databases

always-show-logo yes # Whether to show logs, default is no

### RDB persistence configuration ###
### redis is memory-based, no persistence, data disappears if power is lost
save 900 1 # bgsave for RDB persistence if at least one write operation in 900s
save 300 10
save 60 10000 

stop-writes-on-bgsave-error yes # Whether to continue working after persistence errors

rdbcompression yes # whether to compress the rdb file requires CPU consumption recommend setting to no, to exchange (disk) space for (CPU) time

rdbchecksum yes # whether to save the rdb file for checking

dbfilename dump.rdb # rdb file name

dir . / # rdb file save directory

###AOF configuration###
appendonly yes # The default value is no, which means do not use the AOF incremental persistence method, use the RDB full persistence method
appendfsync everysec # optional values always, everysec, no, suggest to set to everysec

### set password###
requirepass 123456 # Set a more complex password

###Clients###
maxclients 10000 # Maximum number of client connections

maxmemory <bytes> # redis sets the maximum memory capacity

maxmemory-policy noeviction # Policy for handling memory when it reaches the upper limit
1, volatile-lru: LRU only for keys with expiration time set (default)
2、allkeys-lru : remove the key of lru algorithm
3, volatile-random: randomly delete the key that is about to expire
4、allkeys-random:randomly delete
5、volatile-ttl : Delete the soon to expire
6、noeviction : Never expire, return error

###APPEND ONLY MODE aof configuration###
appendonly no # default does not enable aof mode, the default is to use rdb way persistent

appendfilename "appendonly.aof" # Persistent file name

# appendfsync always # sync every time you make a change, which consumes performance
appendfsync everysec # execute sync every second, but may lose this 1s data
# appendfsync no # no sync, OS syncs data itself, fastest

Ysec # executes sync once per second, but the 1s data may be lost

Appendfsync no # if you don’t execute sync, the operating system synchronizes data by itself, and the speed is the fastest


How to Compress them with thumbrails When uploading pictures

When uploading large images, the speed is very slow, so the images are compressed and then stored

Thumbnailator website: http://code.google.com/p/thumbnailator/

Add in POM

   <dependency>
        <groupId>net.coobird</groupId>
        <artifactId>thumbnailator</artifactId>
        <version>0.4.8</version>
    </dependency>

controller

@PostMapping("/upload")
    public Object upload(@RequestParam("file") MultipartFile file) throws IOException {
//        if(file.getSize() > 2 * ONE_MB){
//            return ResponseUtil.fail(500,"Image size exceeds 2M!");
//        }
        String originalFilename = file.getOriginalFilename();
        logger.info("Before compression:"+file.getSize());
        ByteArrayInputStream inputStream = uploadFile(file);
        logger.info("After compression:"+inputStream.available());
        LitemallStorage litemallStorage = storageService.store(inputStream, inputStream.available(), file.getContentType(), originalFilename);
        return ResponseUtil.ok(litemallStorage);
    }

    /**
     * image compression
     * @return
     */
    public static ByteArrayInputStream uploadFile(MultipartFile file){
        if(file == null)return  null;
        ByteArrayOutputStream baos = null;
        try {
            baos = new ByteArrayOutputStream();
            Thumbnails.of(file.getInputStream()).scale(0.4f).outputQuality(0.25f).toOutputStream(baos);
            if(baos!=null)
                return parse(baos);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    // outputStream转inputStream
    public static ByteArrayInputStream parse(OutputStream out) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        baos = (ByteArrayOutputStream) out;
        ByteArrayInputStream swapStream = new ByteArrayInputStream(baos.toByteArray());
        return swapStream;
    }

service:

 /**
     * Store a file object
     *
     * @param inputStream File input stream
     * @param contentLength The length of the file.
     * @param contentType File type
     * @param fileName File index name
     */
    public LitemallStorage store(InputStream inputStream, long contentLength, String contentType, String fileName) {
        String key = generateKey(fileName);
        store(inputStream, contentLength, contentType, key);

        String url = generateUrl(key);
        LitemallStorage storageInfo = new LitemallStorage();
        storageInfo.setName(fileName);
        storageInfo.setSize((int) contentLength);
        storageInfo.setType(contentType);
        storageInfo.setKey(key);
        storageInfo.setUrl(url);
        litemallStorageService.add(storageInfo);

        return storageInfo;
    }


    @Override
    public void store(InputStream inputStream, long contentLength, String contentType, String keyName) {
        try {
            // Simple file upload, supports up to 5 GB, suitable for small file upload, recommend using this interface for files under 20M
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setContentLength(contentLength);
            objectMetadata.setContentType(contentType);
            // The object key (Key) is the unique identifier of the object in the storage bucket.
            PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
            PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }

    }

Other methods of thumbnailator:

//Shrink and put the image by the specified size (will follow the original image height and width ratio)
// Here the image is compressed into a 400×500 thumbnail
Thumbnails.of(fromPic).size(400,500).toFile(toPic);

Zoom in and out according to the specified ratio // Zoom in and out according to the ratio
Thumbnails.of(fromPic).scale(0.2f).toFile(toPic);//scale down and scale up
Thumbnails.of(fromPic).scale(2f);//proportionally enlarge the image size, compress the image file size

// image size remains the same, compress the image file size outputQuality implementation, parameter 1 is the highest quality
Thumbnails.of(fromPic).scale(1f).outputQuality(0.25f).toFile(toPic);