質問編集履歴

2

大変申し訳ございません。ソースコードが無いとのことでしたので、ソースコードを追加しました。

2024/01/28 13:46

投稿

Niyary
Niyary

スコア1

test CHANGED
File without changes
test CHANGED
@@ -7,54 +7,15 @@
7
7
  ### エラーメッセージ
8
8
  ```error
9
9
  Exception in Tkinter callback
10
- Traceback (most recent call last):
10
+
11
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 467, in _make_request
12
- self._validate_conn(conn)
13
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 1096, in _validate_conn
14
- conn.connect()
15
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connection.py", line 642, in connect
16
- sock_and_verified = _ssl_wrap_socket_and_match_hostname(
17
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connection.py", line 782, in _ssl_wrap_socket_and_match_hostname
19
- ssl_sock = ssl_wrap_socket(
20
- ^^^^^^^^^^^^^^^^
21
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\util\ssl_.py", line 470, in ssl_wrap_socket
22
- ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls, server_hostname)
23
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\util\ssl_.py", line 514, in _ssl_wrap_socket_impl
25
- return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
26
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27
- File "C:\Program Files\Python312\Lib\ssl.py", line 455, in wrap_socket
28
- return self.sslsocket_class._create(
29
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30
- File "C:\Program Files\Python312\Lib\ssl.py", line 1046, in _create
31
- self.do_handshake()
32
- File "C:\Program Files\Python312\Lib\ssl.py", line 1321, in do_handshake
33
- self._sslobj.do_handshake()
34
11
  ssl.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)
35
12
 
36
13
  During handling of the above exception, another exception occurred:
37
14
 
38
- Traceback (most recent call last):
39
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 790, in urlopen
40
- response = self._make_request(
41
- ^^^^^^^^^^^^^^^^^^^
42
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 491, in _make_request
43
- raise new_e
44
15
  urllib3.exceptions.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)
45
16
 
46
17
  The above exception was the direct cause of the following exception:
47
18
 
48
- Traceback (most recent call last):
49
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\requests\adapters.py", line 486, in send
50
- resp = conn.urlopen(
51
- ^^^^^^^^^^^^^
52
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\connectionpool.py", line 844, in urlopen
53
- retries = retries.increment(
54
- ^^^^^^^^^^^^^^^^^^
55
- File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\urllib3\util\retry.py", line 515, in increment
56
- raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
57
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
58
19
  urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dm.takaratomy.co.jp', port=443): Max retries exceeded with url: /wp-content/card/cardimage/dm23bd7-017a.jpg (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)')))
59
20
 
60
21
  During handling of the above exception, another exception occurred:
@@ -90,7 +51,168 @@
90
51
  ### 該当のソースコード
91
52
 
92
53
  ```
93
-
54
+ ### 実現したいこと
55
+ SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLEDを解消したい。
56
+
57
+ ### 発生している問題・分からないこと
58
+ SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLEDに対して何をすれば解消するのか分からない
59
+
60
+ ### エラーメッセージ
61
+ ```error
62
+ Exception in Tkinter callback
63
+
64
+ During handling of the above exception, another exception occurred:
65
+
66
+ urllib3.exceptions.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)
67
+
68
+ The above exception was the direct cause of the following exception:
69
+
70
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71
+ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='dm.takaratomy.co.jp', port=443): Max retries exceeded with url: /wp-content/card/cardimage/dm23bd7-017a.jpg (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)')))
72
+
73
+ During handling of the above exception, another exception occurred:
74
+
75
+ ^^^^^^^^^^^^^^^^
76
+ File "C:\Users\81801\Desktop\python\1_DM\test.py", line 176, in btn_click_generate
77
+ find_card_information(conn,driver,cardlink,listcards)
78
+ File "C:\Users\81801\Desktop\python\1_DM\test.py", line 101, in find_card_information
79
+ update_database(conn, elems_head, elems_packname, elems_data, picturl)
80
+ File "C:\Users\81801\Desktop\python\1_DM\test.py", line 65, in update_database
81
+ response = requests.get(picturl)
82
+
83
+ raise SSLError(e, request=request)
84
+ requests.exceptions.SSLError: HTTPSConnectionPool(host='dm.takaratomy.co.jp', port=443): Max retries exceeded with url: /wp-content/card/cardimage/dm23bd7-017a.jpg (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000)')))
85
+ ```
86
+
87
+ ### 該当のソースコード
88
+
89
+ ```
90
+ import os
91
+ ~中略~
92
+
93
+ dbname = r'C:\Users\81801\Desktop\python\1_DM\Duelmasters.db'
94
+ conn = sqlite3.connect(dbname)
95
+
96
+ def update_database(conn, elems_head, elems_packname, elems_data, picturl):
97
+ cur = conn.cursor()
98
+ # 既にデータベース登録済みのカード名はデータベースに登録しない
99
+ duplicate = cur.execute('SELECT * FROM cardlist\
100
+ ~中略~
101
+
102
+ # データベースにないカードのみ、データベースに登録し、画像を保存する
103
+ if duplicate.fetchone() is None:
104
+ sql = 'INSERT INTO cardlist (cardname, ~中略~
105
+
106
+ if len(elems_data) == 11:
107
+ data = (elems_head[0].text,
108
+ elems_packname[0].text,
109
+ picturl,
110
+ ~中略~)
111
+ else:
112
+ data = (elems_head[0].text,
113
+ elems_packname[0].text,
114
+ picturl,
115
+ ~中略~)
116
+ cur.execute(sql, data)
117
+ conn.commit()
118
+
119
+ filename = os.path.basename(picturl)
120
+ response = requests.get(picturl)
121
+ image = response.content
122
+
123
+ with open(filename, "wb") as cardpict:
124
+ cardpict.write(image)
125
+
126
+ def find_card_information(conn,driver,cardlink,listcards):
127
+ for i in range(len(cardlink)):
128
+ if len(cardlink) != 0:
129
+ detail_info = ('https://dm.takaratomy.co.jp'+ cardlink[i].attrs['data-href'])
130
+ driver.get(detail_info)
131
+ time.sleep(5)
132
+
133
+ soup = BeautifulSoup(driver.page_source, 'html.parser')
134
+ elems = soup.find_all('table')
135
+ cards = elems[0].find_all(src=re.compile('/wp-content/card'))
136
+
137
+ for j in range (len(elems)):
138
+ elems_head = elems[j].find_all('th')
139
+ elems_packname = elems[j].find_all('span')
140
+ elems_data = elems[j].find_all('td')
141
+
142
+ if not cards:
143
+ picturl = ('https://dm.takaratomy.co.jp' + listcards[i].attrs['src'])
144
+ else:
145
+ picturl = ('https://dm.takaratomy.co.jp' + cards[0].attrs['src'])
146
+
147
+ if len(elems) == len(cards):
148
+ picturl = ('https://dm.takaratomy.co.jp' + cards[j].attrs['src'])
149
+ update_database(conn, elems_head, elems_packname, elems_data, picturl)
150
+
151
+ def btn_click_lastpage():
152
+
153
+ driver_path = r'C:\chromedriver.exe'
154
+ service = Service(executable_path=driver_path)
155
+ driver = webdriver.Chrome(service=service)
156
+ time.sleep(5)
157
+
158
+ url = 'https://dm.takaratomy.co.jp/card/'
159
+ driver.get(url)
160
+
161
+ soup = BeautifulSoup(driver.page_source, 'html.parser')
162
+ lastpagebtn = soup.find_all(class_='nextpostslink')
163
+ lastpage = lastpagebtn[0].attrs['data-page']
164
+ time.sleep(5)
165
+ driver.close()
166
+ lastpage_data.delete(0, tk.END)
167
+ lastpage_data.insert(tk.END,lastpage)
168
+
169
+ def btn_click_generate():
170
+
171
+ startpage = startpage_data.get()
172
+ tgtpage = tgtpage_data.get()
173
+ lastpage = lastpage_data.get()
174
+
175
+ if startpage == '':
176
+ startpage = '1'
177
+
178
+ ~中略~
179
+
180
+ if (int(startpage) + int(tgtpage)) >= int(lastpage):
181
+ messagebox.showerror('ページ数指定エラー', '最終ページは' + lastpage +
182
+ 'です。開始ページと取得ページ数を見直してください。')
183
+ else:
184
+
185
+ url = ['https://dm.takaratomy.co.jp/card/?v=%7B%22suggest%22:%22on%22,\
186
+ %22keyword_type%22:%5B%22card_name%22,%22card_ruby%22,\
187
+ %22card_text%22%5D,%22culture_cond%22:%5B%22%E5%8D%98%E8%89%B2%22,\
188
+ %22%E5%A4%9A%E8%89%B2%22%5D,%22pagenum%22:%22{}%22,\
189
+ %22samename%22:%22show%22,%22sort%22:%22release_new%22%7D'
190
+ .format(i + int(startpage)) for i in range(int(tgtpage))]
191
+
192
+ for i in range (len(url)):
193
+ conn = sqlite3.connect('Duelmasters.db')
194
+
195
+ driver_path = r"C:\chromedriver.exe"
196
+ service = Service(executable_path=driver_path)
197
+ driver = webdriver.Chrome(service=service)
198
+ time.sleep(5)
199
+
200
+ driver.get(url[i])
201
+ time.sleep(5)
202
+ ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
203
+ ctx.options |= 0x4
204
+
205
+ soup = BeautifulSoup(driver.page_source, 'html.parser')
206
+ cardlink = soup.find_all(class_='cardImage')
207
+ listcards = soup.find_all(src=re.compile('/wp-content/card'))
208
+
209
+ find_card_information(conn,driver,cardlink,listcards)
210
+ conn.close()
211
+ driver.close()
212
+
213
+ root = tk.Tk()
214
+ root.geometry('400x300')
215
+ root.title('Duel Masters database generator')
94
216
  ```
95
217
 
96
218
  ### 試したこと・調べたこと
@@ -104,3 +226,17 @@
104
226
 
105
227
  ### 補足
106
228
  特になし
229
+
230
+ ```
231
+
232
+ ### 試したこと・調べたこと
233
+ - [ ] teratailやGoogle等で検索した
234
+ - [ ] ソースコードを自分なりに変更した
235
+ - [ ] 知人に聞いた
236
+ - [x] その他
237
+
238
+ ##### 上記の詳細・結果
239
+ https://stackoverflow.com/questions/71603314/ssl-error-unsafe-legacy-renegotiation-disabled
240
+
241
+ ### 補足
242
+ 特になし

1

ソースコードを追加しました。

2024/01/28 13:36

投稿

Niyary
Niyary

スコア1

test CHANGED
File without changes
test CHANGED
@@ -90,7 +90,7 @@
90
90
  ### 該当のソースコード
91
91
 
92
92
  ```
93
- 特になし
93
+
94
94
  ```
95
95
 
96
96
  ### 試したこと・調べたこと