[英]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.