teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

解決したためプライバシー情報を削除

2020/11/12 09:15

投稿

suwakou
suwakou

スコア13

title CHANGED
File without changes
body CHANGED
@@ -1,13 +1,13 @@
1
1
  サイト[リンク内容](https://hassiweb-programming.blogspot.com/2018/05/postgresql-control-by-python.html)を参考にPythonからpostgreSQLに接続しようと試みて以下のコードを入力したところ
2
2
  ```
3
3
  import psycopg2
4
- conn = psycopg2.connect(host='133.78.152.136', dbname='sample', user='postgres', password='000', port='5432')
4
+ conn = psycopg2.connect(host='000', dbname='sample', user='postgres', password='000', port='5432')
5
5
  ```
6
6
  以下のエラー
7
7
  ```ここに言語を入力
8
8
  OperationalError Traceback (most recent call last)
9
9
  <ipython-input-3-28a442dcc7b2> in <module>()
10
- ----> 1 conn = psycopg2.connect(host='133.78.152.136', dbname='sample', user='postgres', password='crRirr0322', port='5432')
10
+ ----> 1 conn = psycopg2.connect(host='000', dbname='sample', user='postgres', password='000', port='5432')
11
11
 
12
12
  /usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py in connect(dsn, connection_factory, cursor_factory, **kwargs)
13
13
  128
@@ -17,14 +17,14 @@
17
17
  132 conn.cursor_factory = cursor_factory
18
18
 
19
19
  OperationalError: could not connect to server: Connection timed out
20
- Is the server running on host "133.78.152.136" and accepting
20
+ Is the server running on host "000" and accepting
21
21
  TCP/IP connections on port 5432?
22
22
  ```
23
23
  により接続できていません。以下の二つの可能性を考えました
24
24
 
25
25
  ●接続情報が間違っているのでは
26
- →postGISにはパスワードとユーザーネーム、ポート番号をもってして接続できました。![イメージ説明](162c327211aaed9b62258e450fb6e160.png)
26
+ →postGISにはパスワードとユーザーネーム、ポート番号をもってして接続できました。[解決のため削除](162c327211aaed9b62258e450fb6e160.png)
27
- また、ホスト名はコマンドプロンプトのipconfigで確認したIPv4 アドレス![イメージ説明](31ec3b54a1a7c6b267206e1d98615a6a.png)を入力しています。
27
+ また、ホスト名はコマンドプロンプトのipconfigで確認したIPv4 アドレス![イメージ説明]を入力しています。
28
28
 
29
29
  ●SQL側に問題があるのでは
30
30
  →SQLにスクリプトを書いてデータを保存したり編集は問題なくできました。また、POSTGISとの接続もできるので今のところ問題点は見つかっていないです。