質問編集履歴
2
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -139,8 +139,10 @@
|
|
139
139
|
|
140
140
|
ローカル環境ではこのエラーは起きず、デプロイすると発生します。
|
141
141
|
|
142
|
+
サブスクリプション:Visual Studio Enterprise – MPN
|
143
|
+
場所:西日本
|
144
|
+
App Serviceプラン:B1
|
142
145
|
|
143
|
-
|
144
146
|
なおpython はver3.7.9です。
|
145
147
|
|
146
148
|
お力添えを頂けますと幸いです。
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,10 +1,146 @@
|
|
1
|
-
|
1
|
+
Azure SQL Databaseを用いたウェブアプリを作成し、
|
2
|
-
同じく
|
2
|
+
同じくAzureのWebappにデプロイしました。
|
3
3
|
デプロイした後1日~2日ほどは正常に動作しますが、
|
4
4
|
その後key errorをはくようになります。
|
5
5
|
web app上では動作していない状態でもローカルで
|
6
6
|
デバッグ、実行すると正常に動作します。
|
7
7
|
|
8
|
+
関係ありそうなコードは
|
9
|
+
```python
|
10
|
+
# dao.py
|
11
|
+
class DbManeger:
|
12
|
+
|
13
|
+
server = '〇〇.database.windows.net'
|
14
|
+
database = '〇〇'
|
15
|
+
username = '〇〇'
|
16
|
+
password = '〇〇'
|
17
|
+
|
18
|
+
driver= '{ODBC Driver 17 for SQL Server}'
|
19
|
+
|
20
|
+
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
|
21
|
+
|
22
|
+
cursor = cnxn.cursor()
|
23
|
+
|
24
|
+
select = "SELECT * FROM dbo.users"
|
25
|
+
|
26
|
+
def select_db(self, select):
|
27
|
+
self.cursor.execute(select)
|
28
|
+
rows = self.cursor.fetchall()
|
29
|
+
rows = [list(item) for item in rows]
|
30
|
+
return rows
|
31
|
+
|
32
|
+
def close_db(self):
|
33
|
+
self.cursor.close()
|
34
|
+
self.cnxn.close()
|
35
|
+
|
36
|
+
def execute(self, exe):
|
37
|
+
self.cursor.execute(exe)
|
38
|
+
self.cursor.execute("COMMIT")
|
39
|
+
|
40
|
+
```
|
41
|
+
|
42
|
+
```python
|
43
|
+
# app.py
|
44
|
+
@app.route('/login', methods=["GET", "POST"])
|
45
|
+
def login():
|
46
|
+
if(request.method == "POST"):
|
47
|
+
users = config.get_userlist() # ログイン用ユーザー
|
48
|
+
def nested_dict(): return defaultdict(nested_dict)
|
49
|
+
user_check = nested_dict()
|
50
|
+
for i in users.values():
|
51
|
+
user_check[i.name]["password"] = i.password
|
52
|
+
user_check[i.name]["id"] = i.id
|
53
|
+
user_check[i.name]["data"] = i.data
|
54
|
+
# ユーザーチェック
|
55
|
+
if(request.form["username"] in user_check and request.form["password"] == user_check[request.form["username"]]["password"]):
|
56
|
+
# ユーザーが存在した場合はログイン
|
57
|
+
login_user(users.get(user_check[request.form["username"]]["id"]))
|
58
|
+
session["username"] = request.form["username"]
|
59
|
+
session["password"] = request.form["password"]
|
60
|
+
itemlist = config.ITEM_LIST
|
61
|
+
session["itemlist"] = itemlist[1]
|
62
|
+
|
63
|
+
data_state = user_check[request.form["username"]]["data"]
|
64
|
+
|
65
|
+
session["data_state"] = data_state
|
66
|
+
|
67
|
+
return render_template("index.html",
|
68
|
+
title="〇〇",
|
69
|
+
login_info=login_info_state())
|
70
|
+
else:
|
71
|
+
return render_template("login.html", msg="パスワードが違います。",
|
72
|
+
title="〇〇",
|
73
|
+
login_info=login_info_state())
|
74
|
+
else:
|
75
|
+
return render_template("login.html",
|
76
|
+
title="〇〇",
|
77
|
+
login_info=login_info_state())
|
78
|
+
```
|
79
|
+
```python
|
80
|
+
# config.py
|
81
|
+
def get_itemlist():
|
82
|
+
db_maneger = dao.DbManeger()
|
83
|
+
items = db_maneger.select_db("select * from dbo.hin_list ORDER BY hin_name")
|
84
|
+
items = np.array(items).T.tolist()
|
85
|
+
return items
|
86
|
+
|
87
|
+
ITEM_LIST = get_itemlist()
|
88
|
+
hin_code = ITEM_LIST[0][0]
|
89
|
+
|
90
|
+
db_maneger = DbManeger()
|
91
|
+
past_data = db_maneger.select_db(f"SELECT days.date, days.ave_temp, days.EUR_YEN, hin.tanka, hin.PCR FROM dbo.forecast_days AS days INNER JOIN dbo.forecast_{hin_code} AS hin ON days.date = hin.date")
|
92
|
+
src_data = pd.DataFrame(past_data, columns=["日付", "平均気温(℃)", "ユーロ/円", "単価", "PCR"])
|
93
|
+
|
94
|
+
datelist = src_data["日付"].to_numpy().tolist()
|
95
|
+
FORECAST_PERIOD = f"{datelist[0]}~{datelist[-1]}"
|
96
|
+
|
97
|
+
|
98
|
+
class User(UserMixin):
|
99
|
+
def __init__(self, id, name, password, data):
|
100
|
+
self.id = id
|
101
|
+
self.name = name
|
102
|
+
self.password = password
|
103
|
+
self.data = data
|
104
|
+
|
105
|
+
|
106
|
+
def get_userlist():
|
107
|
+
db_maneger = dao.DbManeger()
|
108
|
+
users = db_maneger.select_db("select * from dbo.users")
|
109
|
+
|
110
|
+
userlist = []
|
111
|
+
|
112
|
+
i = 0
|
113
|
+
for row in users:
|
114
|
+
row.insert(0, i)
|
115
|
+
userlist.append(row)
|
116
|
+
i = i + 1
|
117
|
+
|
118
|
+
userlist = np.array(userlist).T.tolist()
|
119
|
+
|
120
|
+
USERS = {}
|
121
|
+
for i in range(len(userlist[0])):
|
122
|
+
Userr = User(i + 1, userlist[1][i], userlist[2][i], userlist[3][i])
|
123
|
+
USERS[i + 1] = Userr
|
124
|
+
|
125
|
+
return USERS
|
126
|
+
```
|
127
|
+
|
128
|
+
エラーは以下の通りです。
|
129
|
+
File "/tmp/8d967a1d088906d/app.py", line 286, in login
|
130
|
+
users = config.get_userlist()
|
131
|
+
File "/tmp/8d967a1d088906d/config.py", line 65, in get_userlist
|
132
|
+
users = db_maneger.select_db("select * from dbo.users")
|
133
|
+
File "/tmp/8d967a1d088906d/model/dao.py", line 20, in select_db
|
134
|
+
self.cursor.execute(select)
|
135
|
+
pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure (0) (SQLExecDirectW)')
|
136
|
+
"POST /login HTTP/1.1" 500 290 "https://〇〇.azurewebsites.net/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
|
137
|
+
|
138
|
+
2021-09-01T00:21:58.555787350Z key error
|
139
|
+
|
140
|
+
ローカル環境ではこのエラーは起きず、デプロイすると発生します。
|
141
|
+
|
142
|
+
|
143
|
+
|
8
144
|
なおpython はver3.7.9です。
|
9
145
|
|
10
146
|
お力添えを頂けますと幸いです。
|