New Ribbon
Canva+AI創意設計與品牌應用250招:從商業技巧、社群祕技到AI圖文影音特效 快快樂樂學威力導演2024.影音剪輯與AI精彩創作 文淵閣工作室祝福大家新年快樂.龍年吉祥 Power Automate自動化超效率工作術 Midjourney AI圖像魔導書:搭配ChatGPT魔法加倍 超人氣FB+IG+LINE社群經營與行銷力(第二版) 翻倍效率工作術:不會就太可惜的 Excel × ChatGPT 自動化應用 AppInventor2零基礎入門班中文版(第六版) Python零基礎入門班(第四版) C語言學習聖經 用Canva設計超快超質感:平面、網頁、電子書、簡報、影片製作與AI繪圖最速技 PHP8/MySQL網頁程式設計自學聖經 翻倍效率工作術 - 不會就太可惜的Power BI大數據視覺圖表設計與分析(第三版) 社群經營一定要會的影音剪輯與動畫製作術 Notion高效管理250招:筆記×資料庫×團隊協作,數位生活與工作最佳幫手 Office 2021高效實用範例必修16課(附500分鐘影音教學/範例檔) Excel自學聖經(第二版):從完整入門到職場活用的技巧與實例大全 網路開店×拍賣王:蝦皮來了(第二版) 專家都在用的Google最強實戰:表單、文件、試算、簡報、遠距與線上會議 超人氣 Instagram 視覺行銷力(第二版):小編不敗,經營 IG 品牌人氣王的 120 個秘技!

 

  第三章 PostgreSQL 錯誤訊息

陳


更新時間:2021/4/17 下午 09:49:52

 

您好,

在跟著書中下載完postgreSQL後,
打開pgAdmin,要點開server時,會出現

Please enter the password for the user 'postgres' to connect the server - "PostgreSQL 13"

輸入安裝時的密碼後,卻出現錯誤訊息

could not initiate GSSAPI security context: The operation or option is not available: Credential for asked mech-type mech not found in the credential handle FATAL: password authentication failed for user "postgres"

請問我該怎麼解決處理?
謝謝

文淵閣工作室

文淵閣工作室
更新時間:2021/4/19 下午 01:45:44

 

寫書時為PostgreSQL 11,現在移除後安裝PostgreSQL 13,的確新增了
Please enter the password for the user 'postgres' to connect the server - "PostgreSQL 13"
項目,但輸入安裝的密碼後即可正常使用。
因我們沒有發生您的狀況,建議:
1. 查網路https://stackoverflow.com/questions/64748091/postgresql-13-fatal-password-authentication-failed-for-user-postgres,提到重新開機即可,您試試看。
2. 若仍不行,請移除後重新安裝,密碼設成書中的「123456」,因我們是設此密碼正常執行,試試看。

陳


更新時間:2021/4/19 下午 09:06:10

 

您好,

後來解決了。
不知道是不是因為是mac關係,
所以後來是分開安裝
pgadmin 與 postgres

但接下來跟著書裡的
models.py要測試資料庫連線
輸入http://127.0.0.1:5000/
會發生以下錯誤

Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

然後在sublime看到的log則是

sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  database "testdb" does not exist

請問該怎麼解決?謝謝



文淵閣工作室

文淵閣工作室
更新時間:2021/4/19 下午 09:56:07

 

訊息顯示 testdb 資料庫不存在,您有建立 testdb 資料庫嗎?

陳


更新時間:2021/4/20 上午 09:11:40

 

是的,已建立testdb

並在sublime執行後,
輸入http://127.0.0.1:5000/

接著就出現下面一大串log

/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py:872: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(
* Serving Flask app "models" (lazy loading)
* Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2021-04-19 20:04:34,679] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2339, in _wrap_pool_connect
    return fn()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 364, in connect
    return _ConnectionFairy._checkout(self)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
    rec = pool._do_get()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
    self._dec_overflow()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get
    return self._create_connection()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
    return _ConnectionRecord(self)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 440, in __init__
    self.__connect(first_connect_check=True)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 656, in __connect
    connection = pool._invoke_creator(self)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 493, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL:  database "testdb" does not exist


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/hsin-hueichen/Desktop/testdb/models.py", line 24, in index
    db.create_all()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 1094, in create_all
    self._execute_for_all_tables(app, bind, 'create_all')
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/flask_sqlalchemy/__init__.py", line 1086, in _execute_for_all_tables
    op(bind=self.get_engine(app, bind), **extra)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 4546, in create_all
    bind._run_visitor(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2097, in _run_visitor
    with self._optional_conn_ctx_manager(connection) as conn:
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2089, in _optional_conn_ctx_manager
    with self._contextual_connect() as conn:
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2305, in _contextual_connect
    self._wrap_pool_connect(self.pool.connect, None),
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2342, in _wrap_pool_connect
    Connection._handle_dbapi_exception_noconnection(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1584, in _handle_dbapi_exception_noconnection
    util.raise_(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2339, in _wrap_pool_connect
    return fn()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 364, in connect
    return _ConnectionFairy._checkout(self)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
    rec = pool._do_get()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
    self._dec_overflow()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get
    return self._create_connection()
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
    return _ConnectionRecord(self)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 440, in __init__
    self.__connect(first_connect_check=True)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 656, in __connect
    connection = pool._invoke_creator(self)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
    return dialect.connect(*cargs, **cparams)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 493, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/Users/hsin-hueichen/opt/anaconda3/lib/python3.8/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL:  database "testdb" does not exist

(Background on this error at: http://sqlalche.me/e/13/e3q8)
127.0.0.1 - - [19/Apr/2021 20:04:34] " [35m [1mGET / HTTP/1.1 [0m" 500 -

文淵閣工作室

文淵閣工作室
更新時間:2021/4/21 上午 10:36:45

 

我們在WIN10下執行一切都正常,由於我們沒有MAC電腦測試,只能給予以下建議:
1. 請確認建立testdb資料庫的owner為 admin,密碼為123456。
2. 在pgadmin中PostgreSQL 13按滑鼠右鍵,點選 Properties / Connection,確認 PORT 為 5432。
3. 如果仍無法解決,請嚐試在 WIN10 上測試,看是否為 MAC 環境的問題。




 

 

Re:第三章 PostgreSQL 錯誤訊息

請輸入姓名。

已超出字元數目的最大值。


請輸入電子郵件。

格式無效。


請輸入內容。