[英]How to setup psycopg2 with Google App Engine PostgreSQL database
[英]Database setup for Mongodb and Postgresql
将所有文件从 python 2.7 转换为最新版本后,我在运行游戏时遇到了问题。 我收到数据库连接错误。 我有一个文件 Frontend.py 有以下代码:
BIND_PORT = 7071
BIND_ADDRESS = "0.0.0.0"
MONGODB_HOST = "10.0.0.1"
MONGODB_PORT = 27017
DB_USERNAME = "tdta"
DB_PASSWORD = "foobar42"
DB_HOST = "10.0.0.1"
DB_DATABASE = "tdta"
NEW_USER_RATING = 1500
BACKEND_SERVERS = (
( "127.0.0.1", 32073, "th_frontend", "e5e6af02519f110093d76dcc1f55b25d" ),
( "127.0.0.1", 32073, "th_frontend", "e5e6af02519f110093d76dcc1f55b25d" ),
( "127.0.0.1", 32073, "th_frontend", "e5e6af02519f110093d76dcc1f55b25d" ),
)
我有另一个文件 ServerConfig.py 用于后端,代码如下:
SERVER_PORT = 32073
SERVER_FPS = 60.0 # should read back from a config file, but this will do for now
SERVER_FRAME_QUOTA = 2.0/SERVER_FPS
PING_FREQUENCY = 3.0 # once per second if nothing else
LATENCY_BUFFER_LENGTH = 10 # how many latency samples will be stored and averaged to get an average latency measurement
NONACTIVITY_GRACE_PERIOD = 300.0 # if users do absolutely nothing for this amount of seconds the match will be terminated
NONACTIVITY_WARNING_PERIOD = 240.0 # if users do absolutely nothing for this amount of seconds a warning will be sent
VISUALIZE = False
ALLOW_DEBUG = True
ALLOW_DEBUG_COMMANDS = True
MATCH_UNIT_CAP = 400
MONGODB_HOST = "10.0.0.1"
MONGODB_PORT = 27017
FRONTEND_HOST = "127.0.0.1"
FRONTEND_PORT = 7070
FRONTEND_USERNAME = "th_frontend"
FRONTEND_PASSWORD = "e5e6af02519f110093d76dcc1f55b25d"
我知道这个文件需要根据我的 postgresql 和 mongodb 数据库凭据进行配置。
谁能告诉我 th_frontend", "e5e6af02519f110093d76dcc1f55b25d" 是什么?是 postgresql 用户名和密码吗
我确定这适用于 mongodb 连接:
MONGODB_HOST = "10.0.0.1"
MONGODB_PORT = 27017
DB_USERNAME = "tdta"
DB_PASSWORD = "foobar42"
DB_HOST = "10.0.0.1"
DB_DATABASE = "tdta"
但是,当我尝试登录时,使用此凭据显示没有数据库“tdta”,尽管我确信 mongo show dbs 显示了 tdta。
我很困惑
BIND_PORT = 7071
BIND_ADDRESS = "0.0.0.0"
root@vps-99083:/home/Latestfiles/frontend_server# Database exception while getti ng session: TypeError('Secret key missing for non-string Cookie.',); ignored.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/local/lib/python3.6/dist-packages/bottle.py", line 1729, in wrapper
rv = callback(*a, **ka)
File "/usr/local/lib/python3.6/dist-packages/bottle_sqlalchemy.py", line 155, in wrapper
rv = callback(*args, **kwargs)
File "/home/Latestfiles/frontend_server/sessions.py", line 72, in wrapper
return func(sess, user, *a, **k)
File "/home/Latestfiles/frontend_server/metrics.py", line 24, in wrapper
d = func( *a, **k )
File "frontend.py", line 915, in login
user = authenticate(db, request_dict["username"], md5(request_dict["password "]).hexdigest())
TypeError: Unicode-objects must be encoded before hashing
174.250.14.8 - - [2021-06-17 18:36:36] "POST /login HTTP/1.1" 500 885 0.157924
现在尝试从 Unity3D 连接时收到此错误消息。 我仍然无法弄清楚这是什么,因为 mongodb 和 postgresql 具有不同的登录凭据
FRONTEND_USERNAME = "th_frontend"
FRONTEND_PASSWORD = "e5e6af02519f110093d76dcc1f55b25d"
尝试使用 Unity3d 登录时出现错误:
root@vps-99083:/home/Latestfiles/frontend_server# Database exception while getti ng session: TypeError('Secret key missing for non-string Cookie.',); ignored.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/local/lib/python3.6/dist-packages/bottle.py", line 1729, in wrapper
rv = callback(*a, **ka)
File "/usr/local/lib/python3.6/dist-packages/bottle_sqlalchemy.py", line 155, in wrapper
rv = callback(*args, **kwargs)
File "/home/Latestfiles/frontend_server/sessions.py", line 72, in wrapper
return func(sess, user, *a, **k)
File "/home/Latestfiles/frontend_server/metrics.py", line 24, in wrapper
d = func( *a, **k )
File "frontend.py", line 915, in login
user = authenticate(db, request_dict["username"], md5(request_dict["password "]).hexdigest())
TypeError: Unicode-objects must be encoded before hashing
174.250.14.8 - - [2021-06-17 18:36:36] "POST /login HTTP/1.1" 500 885 0.157924
现在尝试从 Unity3D 连接时收到此错误消息。
在snakecharmerb 的帮助下,我得以修复。 我更改了用户名和密码,现在可以登录到 postgresql 数据库。
现在我收到新错误:
root@vps-99083:/home/Latestfiles/frontend_server# Database exception while getti ng session: TypeError('Secret key missing for non-string Cookie.',); ignored.
auth for user test1 with hash 098f6bcd4621d373cade4e832627b4f6 (got 098f6bcd4621 d373cade4e832627b4f6)
test1 authenticating with client version 0.3.0.4...
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/local/lib/python3.6/dist-packages/bottle.py", line 1729, in wrapper
rv = callback(*a, **ka)
File "/usr/local/lib/python3.6/dist-packages/bottle_sqlalchemy.py", line 155, in wrapper
rv = callback(*args, **kwargs)
File "/home/Latestfiles/frontend_server/sessions.py", line 72, in wrapper
return func(sess, user, *a, **k)
File "/home/Latestfiles/frontend_server/metrics.py", line 24, in wrapper
d = func( *a, **k )
File "frontend.py", line 944, in login
d = finalizeLogin( db, session, user, clientversion, clientplatform, screenN ame=user.username)
File "frontend.py", line 443, in finalizeLogin
session.user_id = user.id
AttributeError: 'NoneType' object has no attribute 'user_id'
108.14.69.202 - - [2021-06-18 07:42:51] "POST /login HTTP/1.1" 500 885 0.365024
我该怎么办? 我的id是user1,密码是user
错误信息
类型错误:必须在散列之前对 Unicode 对象进行编码
告诉你你需要在散列之前对密码进行编码,所以行
user = authenticate(db, request_dict["username"], md5(request_dict["password"]).hexdigest())
应该
user = authenticate(db, request_dict["username"], md5(request_dict["password"].encode('ascii')).hexdigest())
(如果密码可能包含非 ASCII 字符,您可能希望使用 UTF-8 作为编码)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.