Google app engine CloudSQL+;谷歌应用引擎
因此,我在应用程序引擎的Django中遇到了很多datetimes问题,但随后我开始跟踪错误,似乎还有更严重的问题。这是我看到的 这是我的数据库:Google app engine CloudSQL+;谷歌应用引擎,google-app-engine,mysql-python,google-cloud-sql,Google App Engine,Mysql Python,Google Cloud Sql,因此,我在应用程序引擎的Django中遇到了很多datetimes问题,但随后我开始跟踪错误,似乎还有更严重的问题。这是我看到的 这是我的数据库: mysql> select * from polls_question; +----+---------------+----------------------------+ | id | question_text | pub_date | +----+---------------+----------
mysql> select * from polls_question;
+----+---------------+----------------------------+
| id | question_text | pub_date |
+----+---------------+----------------------------+
| 1 | test | 2016-02-08 15:24:44.000000 |
+----+---------------+----------------------------+
1 row in set (0.16 sec)
下面是试图读取这些数据的代码:
import MySQLdb
import os
import webapp2
class IndexPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
env = os.getenv('SERVER_SOFTWARE')
if (env and env.startswith('Google App Engine/')):
# Connecting from App Engine
db = MySQLdb.connect(
unix_socket='/cloudsql/<removed>:<removed>',
user='root',db='gaetest')
else:
# Connecting from an external network.
# Make sure your network is whitelisted
db = MySQLdb.connect(
host='<removed>',
port=3306,
user='root', passwd='<removed>',db='<removed>')
cursor = db.cursor()
cursor.execute('SELECT * FROM polls_question')
for r in cursor.fetchall():
self.response.write('%s\n' % str(r))
db.close()
app = webapp2.WSGIApplication([
('/', IndexPage),
])
当我访问远程url时,我得到:
(1L, 'test', None)
不确定我还能做什么,这个例子已经尽可能简化了。有人知道发生了什么事吗?糟糕的是,谷歌通常无法拖延。因此,在花了太多时间之后,我发现了这个问题,数据库是使用django的迁移功能创建的,这导致它创建了一个日期时间(6)(高精度),这些在远程访问站点时不起作用。正常的日期时间工作。因此,改变这些使它工作
问题的原因是我在本地使用了一个支持datetime(6)的较新的mysql python库。这是应用引擎库MySQLDB1.2.4b4的一个错误,在撰写本文时,它也是“最新的”。将MySQLdb的app.yaml依赖项从“最新”或“1.2.4b4”切换到“1.2.5”或“1.2.4”应该可以解决此问题
(1L, 'test', None)