runtime-error 相关问题

在程序执行之后或期间检测到运行时错误。

在 Ubuntu 上使用 Swift 的 URLSession 库从 API 获取数据时出现问题

当尝试使用以下代码从 Swift 调用 API 时,我在运行时收到未知错误,如下所示。使用 Wireshark,我能够确认请求已正确发送到...

回答 1 投票 0

尝试将图像保存到文件夹时出现此错误“PermissionError 13:”。正在保存其他文件,可能是什么问题?

我认为这并不是真正的权限错误,因为某些图像数组正在保存到文件夹中。所有其他文件都在保存,直到这个特定的图像数组。 我检查了文件夹并...

回答 1 投票 0

Constexpr / 编译时常量表达式错误

我的项目在编译时出现以下错误。尝试了一切但无法解决这个问题。 在这里重现错误: https://replit.com/join/egfoiwpgig-darshanpandhi 错误 错误:constexpr

回答 1 投票 0

FLUTTER ERROR 发生异常。 _TypeError(类型“String”不是“index”的“int”类型的子类型)

我想将我的 api 邮递员的数据显示给 flutter,并且我已经成功地获取了我的数据并将其打印在我的终端上。但我无法在模拟器中显示我的数据 但我有这个错误: 例外...

回答 1 投票 0

如何修复“运行时错误:在应用程序上下文之外工作。”使用 Flask 创建蓝图时?

我正在尝试创建蓝图并遇到了这个问题: 回溯(最近一次调用最后一次): 文件“C:\Users\Max\PycharmProjects\python1 lask_first\__init__.py”,第 3 行,位于 中 我正在尝试创建蓝图并遇到了这个问题: Traceback (most recent call last): File "C:\Users\Max\PycharmProjects\python1\flask_first\__init__.py", line 3, in <module> from models import db File "C:\Users\Max\PycharmProjects\python1\flask_first\models.py", line 5, in <module> current_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite3.html' # access to the SQL File "C:\python3.9\lib\site-packages\werkzeug\local.py", line 347, in __getattr__ return getattr(self._get_current_object(), name) File "C:\python3.9\lib\site-packages\werkzeug\local.py", line 306, in _get_current_object return self.__local() File "C:\python3.9\lib\site-packages\flask\globals.py", line 52, in _find_app raise RuntimeError(_app_ctx_err_msg) RuntimeError: Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in some way. To solve this, set up an application context with app.app_context(). See the documentation for more information. 我已经做了很多研究,但没有什么对我有用(或者我只是看起来不够合适)。 这是models.py代码: from flask_sqlalchemy import SQLAlchemy from flask import current_app current_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite3.html' # access to the SQL current_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(current_app) class users(db.Model): __tablename__ = 'users' _id = db.Column('id', db.Integer, primary_key=True) name = db.Column(db.String(80)) email = db.Column(db.String(120)) password = db.Column(db.Integer) def __init__(self, name, email, password): self.name = name self.email = email self.password = password 这就是__init__.py: from datetime import timedelta from flask import Flask from models import db from flask_first.admin.second import second def create_app(): app = Flask(__name__) with app.app_context(): db.init_app(app) return app create_app.secret_key = 'hello world' create_app.permanent_session_lifetime = timedelta(minutes=5) # setting the time for long-lasting session if __name__ == '__main__': db.create_all() create_app.run(debug=True) 这是我的结构的屏幕截图: 在这里我将把我的评论扩展为答案。 Python 逐行执行代码,其中包括 import 语句。正如错误所示,当它进入 __init__.py 并到达 from models import db 行时,它立即跳转到 models.py,并开始在那里执行您的行。 Traceback (most recent call last): File "...\__init__.py", line 3, in <module> from models import db File "...\models.py", line 5, in <module> current_app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.sqlite3.html' 此时,导入的current_app还不存在,因为来自create_app的__init__.py似乎还没有被调用。这是您会收到常见 Flask 错误“在应用程序上下文之外工作:”的地方 RuntimeError: Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in some way. To solve this, set up an application context with app.app_context(). See the documentation for more information. 大多数情况下,您会遇到此类错误,解决方案是重新排序初始化代码。确保 Flask 应用程序实例已经创建在执行其他操作之前。它通常应该是您的代码所做的第一件事。 按照flask-sqlalchemy的快速入门教程,您可以将db对象初始化放在app初始化附近。 # Create app object app = Flask(__name__) # Set configs app.config['...'] = ... # Create db object db = SQLAlchemy(app) app和db对象通常一起驻留在某个顶级主模块中。然后,在需要单独设置每个组件的其他子模块(控制器、模型等)中,从主模块导入 app 和/或 db: from some_main_module import app, db # Do stuff with app and db 对我来说,我只需添加app.app_context().push(),它对我有用! 请参阅下面的完整代码: 文件名是basic.py import os from flask import Flask from flask_sqlalchemy import SQLAlchemy basedir = os.path.abspath(os.path.dirname(__file__)) app = Flask(__name__) app.app_context().push() app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join('data.sqlite') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) class Person(db.Model): # Manual Table Name Choice __tablename__ = 'puppies' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.Text) age = db.Column(db.Integer) def __init__(self, name, age): self.name = name self.age = age def __repr__(self): return f"Person {self.name} is {self.age} Yea/s Old" 运行文件名为:setupdatabase.py from basic import db, Person db.create_all() demo1 = Puppy('Eva', 30) demo2 = Puppy('kawsar', 40) db.session.add_all([demo1, demo2]) db.session.commit()

回答 2 投票 0

具有多个索引变量的分段线性函数 Pyomo

我目前正在使用 Pyomo 模块的优化来对设施位置分配进行建模。对于我的模型,我想采用分段线性函数,约束变量 ha...

回答 1 投票 0

NEXT JS 应用程序中未定义 jQuery

我有两个独立的项目,两者都包含相同的 package.json 依赖项。现在我面临的问题是在一个项目中,以下脚本运行良好: <p>我有两个独立的项目,两者都包含相同的 package.json 依赖项。现在我面临的问题是在一个项目中,下面的脚本运行良好:</p> <pre><code> &lt;Script id=&#34;show-banner&#34; strategy=&#34;afterInteractive&#34;&gt; {`jQuery(function() { scrollinit(&#34;carousel&#34;, 3, 1, true, true, true, true, false);})`} &lt;/Script&gt; </code></pre> <p>在另一个项目中我遇到了这个错误: <a href="https://i.stack.imgur.com/THUrE.jpg" target="_blank"><img src="https://cdn.imgupio.com/i/AWkuc3RhY2suaW1ndXIuY29tL1RIVXJFLmpwZw==" alt=""/></a> 可能的解决方案是什么,因为我尝试了一些解决方案,但它们从未起作用,而且我对下一个js很陌生 这是两个项目的浏览器嵌入内容: <a href="https://i.stack.imgur.com/hnpw6.jpg" target="_blank"><img src="https://cdn.imgupio.com/i/AWkuc3RhY2suaW1ndXIuY29tL2hucHc2LmpwZw==" alt=""/></a> 未运行的 jQuery 的 next.config.js 是:</p> <pre><code> /** @type {import(&#39;next&#39;).NextConfig} */ const isProd = process.env.NODE_ENV === &#39;production&#39;; const { i18n } = require(&#39;./next-i18next.config&#39;); const fs = require(&#39;fs&#39;); const http = require(&#39;http&#39;); module.exports = { // allows you the rewriting of URLs i18n, // allows you to set headers for certain requests async headers() { return []; }, pageExtensions: [&#39;mdx&#39;, &#39;md&#39;, &#39;jsx&#39;, &#39;js&#39;, &#39;tsx&#39;, &#39;ts&#39;], reactStrictMode: true, eslint: { dirs: [&#39;components&#39;, &#39;containers&#39;, &#39;core&#39;, &#39;pages&#39;, &#39;redux&#39;, &#39;shared&#39;, &#39;sockets&#39;, &#39;utils&#39;] }, env: { pubnub: { publishKey: &#39;publishKey&#39;, subscribeKey: &#39;subscribeKey&#39;, uuid: &#39;UUID&#39;, channels: {} }, api: { baseUrl: &#39;{mybaseurl}&#39;, configurationUrl: () =&gt; this.env.api.baseUrl + &#39;clients/config&#39; }, }, basePath: &#39;&#39;, assetPrefix: isProd ? &#39;&#39; : &#39;&#39;, poweredByHeader: false, images: { domains: [&#39;3qqk4c7swve3mhkbo1xpvbtm-wpengine.netdna-ssl.com&#39;, &#39;vepimg.b8cdn.com&#39;, &#39;vepimg1.b8cdn.com&#39;, &#39;images.unsplash.com&#39;] } }; </code></pre> 未运行 jQuery 的 <p>_app.js 如下:</p> <pre><code>import type { AppProps } from &#39;next/app&#39;; // import App from &#39;next/app&#39;; // import { PubNubProvider } from &#39;pubnub-react&#39;; import &#39;../public/styles/globals.css&#39;; import { NextPage } from &#39;next&#39;; import { ReactElement, ReactNode, useEffect } from &#39;react&#39;; import { Provider } from &#39;react-redux&#39;; // import { useSocketTransport } from &#39;../shared/hooks/socket-transport.hook&#39;; import rootStore from &#39;../redux/store&#39;; import { PersistGate } from &#39;redux-persist/lib/integration/react&#39;; import Router, { useRouter } from &#39;next/router&#39;; import { WEB_VITAL_LABEL } from &#39;../shared/constants/webvitals.constants&#39;; import { customVitalsHandler, webVitalsHandler } from &#39;../shared/utils/vitals.utils&#39;; import { IWebVital } from &#39;../shared/models/webvital.model&#39;; // import { useUserStory } from &#39;../shared/hooks/userstory.hook&#39;; import { config } from &#39;../core/configs/dev-config&#39;; import { consoleLogUtils } from &#39;../shared/utils/console-log.utils&#39;; import ServerAPI from &#39;../core/api/server.API&#39;; import { appWithTranslation } from &#39;next-i18next&#39;; import nextI18NextConfig from &#39;../next-i18next.config.js&#39;; import { commonUtils } from &#39;../shared/utils/commons.utils&#39;; import &#39;../shared/extensions&#39;; import Wrapper from &#39;../components/layout/default/wrapper.component&#39;; import { isMobile } from &#39;react-device-detect&#39;; Router.events.on(&#39;routeChangeStart&#39;, (url: string) =&gt; { // debugger; }); const { store, persistor } = rootStore(); type NextPageWithLayout = NextPage &amp; { getLayout?: (page: ReactElement) =&gt; ReactNode; } type AppPropsWithLayout = AppProps &amp; { Component: NextPageWithLayout; props: any; apiResult: any; environmentVariables: any; isLocalhost: boolean; } export function reportWebVitals(metric: IWebVital) { metric.label &amp;&amp; metric.label === WEB_VITAL_LABEL ? webVitalsHandler(metric) : customVitalsHandler(metric); } function MyApp({ Component, environmentVariables, pageProps, apiResult, isLocalhost }: AppPropsWithLayout) { // const { getSocketInstance, stopSocketTransport } = useSocketTransport(); // const socketInstance = getSocketInstance(); // const { initUserStory } = useUserStory(); const router = useRouter(); useEffect(() =&gt; { if (!config.api.isEndpointLoaded &amp;&amp; apiResult) { config.api.configJson = apiResult; config.api.isLocalhost = isLocalhost; config.api.isEndpointLoaded = true; config.defaultLanguage = apiResult.languages.default; config.availableLanguages = commonUtils.convertStringToArray(apiResult.languages.options) ?? []; } if (environmentVariables) { config.envVariables = environmentVariables; } // initUserStory(); // return () =&gt; stopSocketTransport(); }); // get Layout of page if defined, otherwise fallback to Normal Layout // eslint-disable-next-line arrow-body-style const getLayoutFn = () =&gt; { return Component.getLayout ? Component.getLayout(&lt;Component {...pageProps} /&gt;) : Component; }; return ( &lt;&gt; &lt;Provider store={store}&gt; &lt;PersistGate loading={null} persistor={persistor}&gt; {/* &lt;PubNubProvider client={socketInstance}&gt; */} {/* Layout is added here for consistent Layout across pages */} &lt;div className=&#34;main&#34;&gt; {!isMobile &amp;&amp; &lt;Wrapper&gt; &lt;Component {...pageProps} /&gt; &lt;/Wrapper&gt;} {isMobile &amp;&amp; &lt;Component {...pageProps} /&gt;} &lt;/div&gt; {/* {getLayoutFn()} */} {/* &lt;/PubNubProvider&gt; */} &lt;/PersistGate&gt; &lt;/Provider&gt; &lt;/&gt; ); } let isApplicationLoaded = false; // Method to get Serverside Api URL Configuration MyApp.getInitialProps = async ({ Component, ctx }: any) =&gt; { // process.env.newvariable = &#39;Done!!!&#39;; if (ctx &amp;&amp; ctx.req) { // added a dummy commit const processKeys = { ...process.env }; let { host } = ctx.req.headers; let pageProps = {}; // [Todo: Remove] This code needs to be removed let isLocalhost = false; if (!host || host.indexOf(&#39;localhost&#39;) &gt; -1) { isLocalhost = true; } host = &#39;jovenesmercosur2021.com&#39;; // &#39;semex.vfairs.com&#39;; // } // const configurationUrl = config.api.configurationUrl(host); const serverApi = new ServerAPI(); const apiResult = await serverApi.getServerApiUrl(host); if (Component.getInitialProps) { pageProps = await Component.getInitialProps(ctx); } if (ctx.res &amp;&amp; !isApplicationLoaded &amp;&amp; apiResult.languages.default !== &#39;en&#39;) { isApplicationLoaded = true; ctx?.res?.writeHead(307, { Location: &#39;/&#39; + apiResult.languages.default + ctx.req.url }); ctx?.res?.end(); } return { environmentVariables: processKeys, pageProps, apiResult, isLocalhost }; } consoleLogUtils.coloredLog(&#39;Initial Props for Client side&#39;); return { pageProps: {} }; }; export default appWithTranslation(MyApp, nextI18NextConfig); </code></pre> </question> <answer tick="false" vote="0"> <p>首先安装<pre><code>npm i jquery</code></pre> 在你的 jQuery 项目中, 然后将其导入到您的文件中任何需要使用它的地方:</p> <pre><code>import $ from &#39;jquery&#39;; </code></pre> <p>就是这样。</p> </answer> </body></html>

回答 0 投票 0

没有打印功能代码不执行?

我正在使用 pandas 库在 Python 中构建代码 将 pandas 导入为 pd df = pd.read_csv('DefectDatabase1.csv') df['污垢%'] = '' 对于 df['Schedule #'].unique() 中的 i: x = df.loc[df['时间表#']==i] #...

回答 1 投票 0

在Python中运行程序时中断

当我在终端中运行此代码**时,我应该按“enter”键在第6行之后运行** 我不知道问题所在 我正在学习python过程中 预先感谢大家.............. 打印...

回答 1 投票 0

如何解决在M1上编译时“可执行文件中的CPU类型错误”?

我在 M1 和 Intel Mac 上使用 XCode 14.2。在“构建设置”中,在“调试”和“发布”的“架构”中设置“标准架构”条目(Apple Silicon,

回答 1 投票 0

未捕获(承诺中)错误:无法读取未定义的属性(读取“_RUNTIME_”)

我有一个 React (v18) 项目,我做了一些事情,现在导致开发工具中出现错误。似乎没有破坏我的任何流程。该错误并未将我指向任何代码行,但是

回答 1 投票 0

SSL 错误不安全旧版重新协商已禁用

我正在运行Python代码,我必须从HTTPSConnectionPool(host='ssd.jpl.nasa.gov', port=443)获取一些数据。但每次我尝试运行代码时都会出现以下错误。我使用的是 MAC OS 1...

回答 10 投票 0

有没有一种方法可以在之间传输数据而不会出现“无效的获取索引'碰撞'(基于:'字符串')”错误?

我正在尝试将数据从一个场景传输到另一个场景以实现简单的模式弹出。我使用传感器来感测玩家是否经过某个区域(使用具有碰撞形状2D 的节点),然后更新

回答 1 投票 0

类型错误:无法读取未定义的属性“xp”

我在 Visual Studio Code 中没有收到任何错误。但是,当我在浏览器中的 Coursera 上运行代码时,我收到类型错误代码“TypeError:无法读取未定义的属性‘xp’”。该代码运行良好...

回答 1 投票 0

运行时错误:将无符号偏移量添加到 0x6030000000d0 溢出到 0x6030000000cc (stl_vector.h)

问题名称:山数组中的峰值索引 该问题需要找到山数组中峰元素的索引。峰值元素定义为大于其邻居的元素...

回答 1 投票 0

尝试在 Android 应用程序中启动“MainActivity”时出现“java.lang.ClassNotFoundException”

我在开发 Android 应用程序时面临一个令人困惑的问题,非常感谢您的见解。尽管仔细检查了我的代码和配置,我还是遇到了 java.lang。

回答 1 投票 0

ironpdf RuntimeError:无法创建 .NET 运行时

我正在通过此链接关注ironpdf的pdf阅读器教程 但我收到了这个错误: -------------------------------------------------- ------------------------ 运行时错误...

回答 1 投票 0

为什么我只导入文件中的函数,导入的文件就自动执行了?

我有一个名为“intro_to_tkinter.py”的文件,在该文件中我从另一个名为“demos_tkinter.py”的文件导入了一个函数“print Something()”。每当我执行...

回答 1 投票 0

尝试在函数中创建 PhotoImage 会出现错误:运行时错误:创建图像太早:没有默认根窗口

我正在尝试从目录中选择一个图像,然后在我的 tkinter 窗口中使用它(我使用的是 customtkinter,所以它本质上是 CTk,但它的工作方式就像 tkinter)并且它的命令执行 w...

回答 1 投票 0

Paramiko 认证失败/认证异常

我正在使用 python paramiko 连接到 SFTP 门户。但是,每次我运行此代码时都会失败并出现此错误 paramiko.ssh_exception.AuthenticationException:身份验证失败。 这是...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.