我有时会收到此错误(有时正常,有时错误):
sqlalchemy.exc.OperationalError: (OperationalError) MySQL Connection not available.
Run Code Online (Sandbox Code Playgroud)
使用时session.query
我正在使用 Flask 和 SQLAlchemy (MySQL) 编写一个简单的服务器。我的app.py
这样:
Session = sessionmaker(bind=engine)
session = Session()
@app.route('/foo')
def foo():
try:
session.query(Foo).all()
except Exception:
session.rollback()
Run Code Online (Sandbox Code Playgroud)
更新
我还在session
另一个文件中创建新的并调用它app.py
Session = sessionmaker(bind=engine)
session = Session()
def foo_helper(): #call in app.py
session.query(Something).all()
Run Code Online (Sandbox Code Playgroud)
更新 2
我的engine
:
engine = create_engine('path')
Run Code Online (Sandbox Code Playgroud)
我怎样才能避免这个错误?
谢谢你!
我创建了一个Short
只需要识别的实体.
这是我生成的代码:
public Source(Short id, String name) {
this.id = id;
this.name = name;
}
Run Code Online (Sandbox Code Playgroud)
TestCode DatabaseHelperTest.java
:
public void testInsertAndLoad(){
Source source = new Source((short) 0, "TestSource");
SourceDao sourceDao = daoSession.getSourceDao(); //#line 26
sourceDao.insert(source);
Short id = source.getId();
assertNotNull(id);
}
Run Code Online (Sandbox Code Playgroud)
当我运行测试时,我得到了ClassCastException:
Running tests
Test running started
java.lang.ClassCastException: java.lang.Short cannot be cast to java.lang.Long
at de.greenrobot.dao.identityscope.IdentityScopeLong.put(IdentityScopeLong.java:31)
at de.greenrobot.dao.AbstractDao.attachEntity(AbstractDao.java:695)
at de.greenrobot.dao.AbstractDao.updateKeyAfterInsertAndAttach(AbstractDao.java:362)
at de.greenrobot.dao.AbstractDao.executeInsert(AbstractDao.java:355)
at de.greenrobot.dao.AbstractDao.insert(AbstractDao.java:293)
at com.tuanchau.DatabaseHelperTest.testInsertAndLoad(DatabaseHelperTest.java:26)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Run Code Online (Sandbox Code Playgroud)
那么,GreenDAO是否允许 …
我想在用户点击视图时捕获事件。当前,我使用TouchableXXX
组件来捕获用户onPress
(似乎仅onPress
捕获onTapDown
事件)。
这是我的项目结构:
/project
| /package
| | __init__.py
| | module1.py
| | module2.py
| main.py
Run Code Online (Sandbox Code Playgroud)
在 中main.py
,我导入module1.py
. 在module1.py
,我导入module2.py
:
from package import module2
#do something
Run Code Online (Sandbox Code Playgroud)
我运行python main.py
正常。但是当我跑python module1.py
(inside package
) 或python /package/module1.py
(inside project
) 时,我得到ImportError
:
Traceback (most recent call last):
File "package/module1.py", line 5, in <module>
from package import engine
ImportError: No module named 'package'
Run Code Online (Sandbox Code Playgroud)
当我module1.py
在 PyCharm 中运行时,一切正常。
所以,我的问题是:如何在module1.py
没有 …
我正在用Django 1.6和Python 3.4编写一个演示代理服务器.当响应具有此标头时,我收到错误:
Transfer-Encoding=chunked
Run Code Online (Sandbox Code Playgroud)
错误是:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
return self.application(environ, start_response)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 214, in __call__
start_response(force_str(status), response_headers)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 236, in start_response
assert not is_hop_by_hop(name),"Hop-by-hop headers not allowed"
AssertionError: Hop-by-hop headers not allowed
Run Code Online (Sandbox Code Playgroud)
我发现了这个问题:在Django代理中间件中允许逐跳头,但看起来像Django 1.6没有basehttp._hop_headers
.
我运行服务器python3.4 manage.py runserver
.
请帮忙
python ×3
android ×1
chunked ×1
console ×1
django ×1
flask ×1
greendao ×1
module ×1
mysql ×1
orm ×1
primary-key ×1
react-native ×1
sqlalchemy ×1
wsgi ×1