質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -280,7 +280,11 @@
|
|
280
280
|
|
281
281
|
|
282
282
|
|
283
|
-
|
283
|
+
サブスクリプション:Visual Studio Enterprise – MPN
|
284
|
+
|
285
|
+
場所:西日本
|
286
|
+
|
287
|
+
App Serviceプラン:B1
|
284
288
|
|
285
289
|
|
286
290
|
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
Azure SQL Databaseを用いたウェブアプリを作成し、
|
2
|
-
|
2
|
+
|
3
|
-
同じく
|
3
|
+
同じくAzureのWebappにデプロイしました。
|
4
4
|
|
5
5
|
デプロイした後1日~2日ほどは正常に動作しますが、
|
6
6
|
|
@@ -12,6 +12,278 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
+
関係ありそうなコードは
|
16
|
+
|
17
|
+
```python
|
18
|
+
|
19
|
+
# dao.py
|
20
|
+
|
21
|
+
class DbManeger:
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
server = '〇〇.database.windows.net'
|
26
|
+
|
27
|
+
database = '〇〇'
|
28
|
+
|
29
|
+
username = '〇〇'
|
30
|
+
|
31
|
+
password = '〇〇'
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
driver= '{ODBC Driver 17 for SQL Server}'
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
cursor = cnxn.cursor()
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
select = "SELECT * FROM dbo.users"
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def select_db(self, select):
|
52
|
+
|
53
|
+
self.cursor.execute(select)
|
54
|
+
|
55
|
+
rows = self.cursor.fetchall()
|
56
|
+
|
57
|
+
rows = [list(item) for item in rows]
|
58
|
+
|
59
|
+
return rows
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
def close_db(self):
|
64
|
+
|
65
|
+
self.cursor.close()
|
66
|
+
|
67
|
+
self.cnxn.close()
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
def execute(self, exe):
|
72
|
+
|
73
|
+
self.cursor.execute(exe)
|
74
|
+
|
75
|
+
self.cursor.execute("COMMIT")
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
```
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```python
|
84
|
+
|
85
|
+
# app.py
|
86
|
+
|
87
|
+
@app.route('/login', methods=["GET", "POST"])
|
88
|
+
|
89
|
+
def login():
|
90
|
+
|
91
|
+
if(request.method == "POST"):
|
92
|
+
|
93
|
+
users = config.get_userlist() # ログイン用ユーザー
|
94
|
+
|
95
|
+
def nested_dict(): return defaultdict(nested_dict)
|
96
|
+
|
97
|
+
user_check = nested_dict()
|
98
|
+
|
99
|
+
for i in users.values():
|
100
|
+
|
101
|
+
user_check[i.name]["password"] = i.password
|
102
|
+
|
103
|
+
user_check[i.name]["id"] = i.id
|
104
|
+
|
105
|
+
user_check[i.name]["data"] = i.data
|
106
|
+
|
107
|
+
# ユーザーチェック
|
108
|
+
|
109
|
+
if(request.form["username"] in user_check and request.form["password"] == user_check[request.form["username"]]["password"]):
|
110
|
+
|
111
|
+
# ユーザーが存在した場合はログイン
|
112
|
+
|
113
|
+
login_user(users.get(user_check[request.form["username"]]["id"]))
|
114
|
+
|
115
|
+
session["username"] = request.form["username"]
|
116
|
+
|
117
|
+
session["password"] = request.form["password"]
|
118
|
+
|
119
|
+
itemlist = config.ITEM_LIST
|
120
|
+
|
121
|
+
session["itemlist"] = itemlist[1]
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
data_state = user_check[request.form["username"]]["data"]
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
session["data_state"] = data_state
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
return render_template("index.html",
|
134
|
+
|
135
|
+
title="〇〇",
|
136
|
+
|
137
|
+
login_info=login_info_state())
|
138
|
+
|
139
|
+
else:
|
140
|
+
|
141
|
+
return render_template("login.html", msg="パスワードが違います。",
|
142
|
+
|
143
|
+
title="〇〇",
|
144
|
+
|
145
|
+
login_info=login_info_state())
|
146
|
+
|
147
|
+
else:
|
148
|
+
|
149
|
+
return render_template("login.html",
|
150
|
+
|
151
|
+
title="〇〇",
|
152
|
+
|
153
|
+
login_info=login_info_state())
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
```python
|
158
|
+
|
159
|
+
# config.py
|
160
|
+
|
161
|
+
def get_itemlist():
|
162
|
+
|
163
|
+
db_maneger = dao.DbManeger()
|
164
|
+
|
165
|
+
items = db_maneger.select_db("select * from dbo.hin_list ORDER BY hin_name")
|
166
|
+
|
167
|
+
items = np.array(items).T.tolist()
|
168
|
+
|
169
|
+
return items
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
ITEM_LIST = get_itemlist()
|
174
|
+
|
175
|
+
hin_code = ITEM_LIST[0][0]
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
db_maneger = DbManeger()
|
180
|
+
|
181
|
+
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")
|
182
|
+
|
183
|
+
src_data = pd.DataFrame(past_data, columns=["日付", "平均気温(℃)", "ユーロ/円", "単価", "PCR"])
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
datelist = src_data["日付"].to_numpy().tolist()
|
188
|
+
|
189
|
+
FORECAST_PERIOD = f"{datelist[0]}~{datelist[-1]}"
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
class User(UserMixin):
|
196
|
+
|
197
|
+
def __init__(self, id, name, password, data):
|
198
|
+
|
199
|
+
self.id = id
|
200
|
+
|
201
|
+
self.name = name
|
202
|
+
|
203
|
+
self.password = password
|
204
|
+
|
205
|
+
self.data = data
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
def get_userlist():
|
212
|
+
|
213
|
+
db_maneger = dao.DbManeger()
|
214
|
+
|
215
|
+
users = db_maneger.select_db("select * from dbo.users")
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
userlist = []
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
i = 0
|
224
|
+
|
225
|
+
for row in users:
|
226
|
+
|
227
|
+
row.insert(0, i)
|
228
|
+
|
229
|
+
userlist.append(row)
|
230
|
+
|
231
|
+
i = i + 1
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
userlist = np.array(userlist).T.tolist()
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
USERS = {}
|
240
|
+
|
241
|
+
for i in range(len(userlist[0])):
|
242
|
+
|
243
|
+
Userr = User(i + 1, userlist[1][i], userlist[2][i], userlist[3][i])
|
244
|
+
|
245
|
+
USERS[i + 1] = Userr
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
return USERS
|
250
|
+
|
251
|
+
```
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
エラーは以下の通りです。
|
256
|
+
|
257
|
+
File "/tmp/8d967a1d088906d/app.py", line 286, in login
|
258
|
+
|
259
|
+
users = config.get_userlist()
|
260
|
+
|
261
|
+
File "/tmp/8d967a1d088906d/config.py", line 65, in get_userlist
|
262
|
+
|
263
|
+
users = db_maneger.select_db("select * from dbo.users")
|
264
|
+
|
265
|
+
File "/tmp/8d967a1d088906d/model/dao.py", line 20, in select_db
|
266
|
+
|
267
|
+
self.cursor.execute(select)
|
268
|
+
|
269
|
+
pyodbc.OperationalError: ('08S01', '[08S01] [Microsoft][ODBC Driver 17 for SQL Server]Communication link failure (0) (SQLExecDirectW)')
|
270
|
+
|
271
|
+
"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"
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
2021-09-01T00:21:58.555787350Z key error
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
ローカル環境ではこのエラーは起きず、デプロイすると発生します。
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
|
286
|
+
|
15
287
|
なおpython はver3.7.9です。
|
16
288
|
|
17
289
|
|