Author Archives: Robins

[Solved] Vite build & Flask Error: Failed to load module script. Strict MIME type checking is enforced

Vite build & Flask Error: Failed to load module script. Strict MIME type checking is enforced


Stack Overflow

questions

I have this HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link
        rel="stylesheet"
        href="../../../static/css/style.css"
        type="text/css" />
    <link
        rel="stylesheet"
        href="../../../static/css/user_header.css"
        type="text/css" />

    <!--suppress HtmlUnknownTarget -->
    <link rel="shortcut icon" href="/favicon.png">

    <script type="module" src="../../../static/js/node_connect.js" ></script>  <-- Error
    <script src="../../../static/lib/jquery.min.js"></script>
    <script src="../../../static/lib/selfserve.js"></script>   

</head>

The problem is node_connect.jsfile. Start the flash web tool locally (Python 3.7.2), and the console will report the following error when opening the page:

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain".
Strict MIME type checking is enforced for module scripts per HTML spec.

Check Title:

Content-Type: text/plain; charset=utf-8

However, in production (when starting through gunicorn), it gives:

Content-Type: application/javascript; charset=utf-8

I guess the web server (APACHE) serves them in the production case, but another thing is that when testing other pages of the web tool, they all work and load JavaScript files correctly (even if their content type is text/plain text). However, the difference is that I notice that in the type.

This applies to my situation:

<script src="../../static/js/translator/library/materialize.js"></script>

Or this:

<script type="application/javascript" src="../../static/js/translator/library/materialize.js"></script>

Of course, I tried this for the problematic JavaScript . File and received the following error (which means it is now loaded):

Uncaught SyntaxError: Cannot use import statement outside a module

According to my research, this basically means that I need to set the type to module (but this will make the browser reject .js files).

Who can help me solve this problem?

best answer:

The problem is caused by flash how to guess the content type of each static file
Import mimetypes from flash and call mimeType, encoding = mimetypes guess_type (download_name) this module creates a database of known MIME types from multiple sources and uses it to return MIME types
Linux and MacOS: look at the mimetypes.py files:

knownfiles = [
    "/etc/mime.types",
    "/etc/httpd/mime.types",                    # Mac OS X
    "/etc/httpd/conf/mime.types",               # Apache
    "/etc/apache/mime.types",                   # Apache 1
    "/etc/apache2/mime.types",                  # Apache 2
    "/usr/local/etc/httpd/conf/mime.types",
    "/usr/local/lib/netscape/mime.types",
    "/usr/local/etc/httpd/conf/mime.types",     # Apache 1.2
    "/usr/local/etc/mime.types",                # Apache 1.3
    ]

But in windows, it will look in the registry:

with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
    for subkeyname in enum_types(hkcr):
        try:
            with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                # Only check file extensions
                if not subkeyname.startswith("."):
                    continue
                # raises OSError if no 'Content Type' value
                mimetype, datatype = _winreg.QueryValueEx(
                    subkey, 'Content Type')
                if datatype != _winreg.REG_SZ:
                    continue
                self.add_type(mimetype, subkeyname, strict)

So to solve the problem, flask thinks JS file is actually a problem of text/plain , just open regedit and adjust this registry key to application/javaScript .

solutions for vite:

Find the registry value, double-click content type to change it to Application/JavaScript , and then restart the computer

if not, please see if your suffix is simple .js, if it is .1242342.js , must be changed to pure .JS suffix can take effect

In order to completely eradicate the disadvantages of modifying files, we can change the configuration file of vite , and modify the name of the output JS file by using the custom packaging option rollupOptions.

Reference: vite2 how to set the file name after packaging

Other configuration items of vite.config.js are shown on the official website. Click here to view more configuration items on the official website.

Python: How to Disable InsecureRequestWarning error

Python Disable InsecureRequestWarning error

Send HTTPS requests using Python 3 requests. When SSL authentication is turned off (verify = false):

import requests
response = requests.get(url='http://127.0.0.1:12345/test', verify=False)

Error Messages:

InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

Solution:

#python3
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

#python2
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

PS: as shown below, disable_warnings() will disable all warning types.

def disable_warnings(category=exceptions.HTTPWarning):
    """
    Helper for quickly disabling all urllib3 warnings.
    """
    warnings.simplefilter("ignore", category)

[Solved] VScode Run C++ File Error: fatal error:opencv2\core.hpp:No such file or diretory

Run c++ file with vscode error: fatal error: opencv2\core.hpp:No such file or diretory

The main error is that the corresponding header file cannot be found in the header file directory!
C header file directory %MINGW_PATH%/include under the header file, which has strcpy and other c function declaration.
C++ header file directory %MINGW_PATH%/lib/gcc/mingw32/4.4.0/include/c++ under the header file, which has the declaration of std::string class.
//home directory
MINGW_PATH=D:/MinGW

//C header file directory
C_INCLUDE_PATH=%MINGW_PATH%/include;%MINGW_PATH%/lib/gcc/mingw32/3.4.5/include

//C++ header file directory
CPLUS_INCLUDE_PATH=%MINGW_PATH%/include/c++/3.4.5;%MINGW_PATH%/include/c++/3.4.5/mingw32;%MINGW_PATH%/include/c++/3.4.5/backward;% C_INCLUDE_PATH%

//In QTSDK with MinGW the C++ header files are in the lib folder
CPLUS_INCLUDE_PATH=%MINGW_PATH%/lib/gcc/mingw32/4.4.0/include/c++;%C_INCLUDE_PATH%

//library directory
LIBRARY_PATH=%MINGW_PATH%/lib;%MINGW_PATH%/lib/gcc/mingw32/3.4.5

//executable program directory
PATH=%MINGW_PATH%/bin;%MINGW_PATH%/libexec/gcc/mingw32/3.4.5

[Solved] JSONUtil.toJsonStr() Error: org.springframework.web.util.NestedServletException: Handler dispatch failed…

hutool tool JSONUtil.toJsonStr() error:

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.StackOverflowError
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1053)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.yx.config.security.permission.MyFilterSecurityInterceptor.invoke(MyFilterSecurityInterceptor.java:48)
	at com.yx.config.security.permission.MyFilterSecurityInterceptor.doFilter(MyFilterSecurityInterceptor.java:42)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.yx.config.web.request.HttpServletFilter.doFilter(HttpServletFilter.java:30)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:320)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at com.yx.config.security.permission.MyFilterSecurityInterceptor.invoke(MyFilterSecurityInterceptor.java:48)
	at com.yx.config.security.permission.MyFilterSecurityInterceptor.doFilter(MyFilterSecurityInterceptor.java:42)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:119)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at com.yx.config.security.jwt.JWTAuthenticationFilter.doFilterInternal(JWTAuthenticationFilter.java:106)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
	at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:96)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:41002)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.StackOverflowError

The reason is that the incoming data is an entity class

Solution: just income vo or dto is OK

[Solved] AgilePLM error: Ora-00904: “A”.”ITEM_NUMBER”: invalid identifier

AgilePLM error

Problem phenomenon

Agile version: 9.3.2

When searching for a material in full-text search, the error is report: ora-00904: “A”.”ITEM_NUMBER”:invalid identifier

However, no error will be reported when using advanced search to specify material search. Restart the database, restart the application and rebuild the index can not be solved.

Cause analysis

In the troubleshooting process, advanced search was used to search all objects one by one. Finally, it was found that the separate search price times was wrong. Later, the administrator remembered that he had changed a price standard in the morning and used the material code as the price standard. The problem may be caused by this operation.

Problem-solving

If the standard is changed, the material code cannot be used as the price standard. Then restart the agile application server. To solve the problem.

[Solved] target_link_libraries error: a missing vtable usually means the first non-inline virtual member function has no definition.

target_link_libraries error:

When compiling a project with cmake, the following appears:

NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.

Cmake:

target_link_libraries(target target1 target2)

In this way, Target1 and target2 libraries need to be used when linking target. However, if Target1 also uses target2, you need to add additional:

target_link_libraries(target1 target2)

Otherwise, when the link generates Target1, you can’t find anything in target2. If target uses Target1 link again, it will definitely report an error.

[Solved] sed -i error: sed: -e expression #1, char 44: invalid reference \1 on `s’ command’s RHS

How to Solve sed -i error:

sed -i.bak '/.*CMDLINE_LINUX.*/s#(.*)"#\1 net.ifnames=0"#' /etc/default/grub

always report the error: sed: -e expression #1, char 44: invalid reference \1 on `s’ command’s RHS

sed -i -r '/.*CMDLINE_LINUX.*/s#(.*)"#\1 net.ifnames=0"#' /etc/default/grub

Later we know that you need to add -r, because there is a backward reference – \1, and -i and -r should be written separately

[Solved] Spring set xml Component Scanning error: Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException…

Spring set xml Component Scanning error

Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in XML document from class path resource [applicationConfig.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 62; cvc-complex-type.2.4.c: The wildcard match is comprehensive, but the declaration of the element ‘context:component-scan’ cannot be found.

Reason:
applicationConfig configurate schemaLocation error:

Solution:

Done!!!

[Solved] mysql-community-server Install Error: error: Failed dependenice…

mysql-community-server Install Error: error: Failed dependenice…

1. Problems encountered

There is no problem installing MySQL community common, MySQL community LIBS and MySQL community client, but there is an error when installing MySQL community server. There is a lack of libaio dependency

2. Solve problems

Execute the command: yum - y install libaio
execute the command: rpm -ivh mysql-community-server-5.7.38-1.el7.x86_64.rpm

[Solved] Element form method resetfields() error: vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of undefined (reading ‘indexOf’)

Element form method resetfields() error

Codes:

// Form Reset
export function resetForm(refName) {
    // The purpose of adding the if condition is to solve the problem of non-existent objects in the console
    if (this.$refs[refName] ) {
        this.$refs[refName].resetFields();
    }
}

 

Error Messages:

vue.runtime.esm.js?2b0e:1888 TypeError: Cannot read properties of undefined (reading 'indexOf')
    at VueComponent.resetField (element-ui.common.js?5c96:23528)
    at eval (element-ui.common.js?5c96:22945)
    at Array.forEach (<anonymous>)
    at VueComponent.resetFields (element-ui.common.js?5c96:22944)
    at VueComponent.resetForm (ruoyi.js?c38a:51)
    at VueComponent.reset (index.vue?6ced:2165)
    at VueComponent.handleCopy (index.vue?6ced:2504)
    at click (index.vue?e6ab:1003)
    at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
    at VueComponent.invoker (vue.runtime.esm.js?2b0e:2179)

 

Solution:

// Form reset
export function resetForm(refName) {
// The purpose of adding the if condition is to solve the problem of non-existent objects in the console
    if (this.$refs[refName] !== undefined) {
        this.$refs[refName].resetFields();
    }
}

 

Another possibility for this type of problem is that the prop is not assigned a value, and a similar problem can occur:

 <el-form-item label="Self-pickup offer">
              <el-input
                v-model="form.selfOffer"
                :clearable="true"
                :disabled="disabled"
                placeholder="Please enter a discount price"
                @input="inputCityFloat"
              >
                <template slot="append">Yuan</template>
              </el-input>
            </el-form-item>

 

[Solved] Router Pinia error: getActivePinia was called with no active Pinia. Did you forget to install pinia

Router Pinia error: getActivePinia was called with no active Pinia. Did you forget to install pinia
Solution:1. First create the store TS file

import { createPinia } from "pinia";
const pinia = createpinia();
export default pinia;
Instead of the kind of form created in main.ts.

2. Import in Mian.ts

// Alternative to the traditional direct import in main.ts
import { createApp } from "vue"
import App from './App.vue'
import pinia from "./store/store"

const app = createApp(App)
app.use(pinia)

3. Using Pinia in router.ts

import { createRouter, createWebHistory } from 'vue-router'
import pinia from '../store/store' 
import { useUser} from "../store/useUser"
const store = useUser(pinia)  // Make sure to pass in pinia here
console.log(store) 
After that, you can use the methods and properties of the store as you like