【发布时间】:2016-05-19 09:53:29
【问题描述】:
所以我在 App Engine 上的 Django 中遇到了很多日期时间问题,但后来我开始跟踪错误,似乎还有更严重的问题。这就是我所看到的。
这是我的数据库:
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),
])
在我的电脑上它给了我:
(1L, 'test', datetime.datetime(2016, 2, 8, 15, 24, 44))
当我访问远程网址时,我得到:
(1L, 'test', None)
不知道我还能做些什么,这个例子已经尽可能地简化了。有谁知道发生了什么?太糟糕了,谷歌通常无法拖延。
【问题讨论】:
标签: google-app-engine mysql-python google-cloud-sql