実現したいこと
SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLEDを解消したい。
発生している問題・分からないこと
SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLEDに対して何をすれば解消するのか分からない
エラーメッセージ
error
1Exception in Tkinter callback 2 3ssl.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000) 4 5During handling of the above exception, another exception occurred: 6 7urllib3.exceptions.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000) 8 9The above exception was the direct cause of the following exception: 10 11urllib3.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)'))) 12 13During handling of the above exception, another exception occurred: 14 15Traceback (most recent call last): 16 File "C:\Program Files\Python312\Lib\tkinter\__init__.py", line 1962, in __call__ 17 return self.func(*args) 18 ^^^^^^^^^^^^^^^^ 19 File "C:\Users\81801\Desktop\python\1_DM\test.py", line 176, in btn_click_generate 20 find_card_information(conn,driver,cardlink,listcards) 21 File "C:\Users\81801\Desktop\python\1_DM\test.py", line 101, in find_card_information 22 update_database(conn, elems_head, elems_packname, elems_data, picturl) 23 File "C:\Users\81801\Desktop\python\1_DM\test.py", line 65, in update_database 24 response = requests.get(picturl) 25 ^^^^^^^^^^^^^^^^^^^^^ 26 File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\requests\api.py", line 73, in get 27 return request("get", url, params=params, **kwargs) 28 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 29 File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\requests\api.py", line 59, in request 30 return session.request(method=method, url=url, **kwargs) 31 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 32 File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\requests\sessions.py", line 589, in request 33 resp = self.send(prep, **send_kwargs) 34 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 35 File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\requests\sessions.py", line 703, in send 36 r = adapter.send(request, **kwargs) 37 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 38 File "C:\Users\81801\AppData\Roaming\Python\Python312\site-packages\requests\adapters.py", line 517, in send 39 raise SSLError(e, request=request) 40requests.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)')))
該当のソースコード
### 実現したいこと SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLEDを解消したい。 ### 発生している問題・分からないこと SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLEDに対して何をすれば解消するのか分からない ### エラーメッセージ ```error Exception in Tkinter callback During handling of the above exception, another exception occurred: urllib3.exceptions.SSLError: [SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1000) The above exception was the direct cause of the following exception: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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)'))) During handling of the above exception, another exception occurred: ^^^^^^^^^^^^^^^^ File "C:\Users\81801\Desktop\python\1_DM\test.py", line 176, in btn_click_generate find_card_information(conn,driver,cardlink,listcards) File "C:\Users\81801\Desktop\python\1_DM\test.py", line 101, in find_card_information update_database(conn, elems_head, elems_packname, elems_data, picturl) File "C:\Users\81801\Desktop\python\1_DM\test.py", line 65, in update_database response = requests.get(picturl) raise SSLError(e, request=request) 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)')))
該当のソースコード
import os ~中略~ dbname = r'C:\Users\81801\Desktop\python\1_DM\Duelmasters.db' conn = sqlite3.connect(dbname) def update_database(conn, elems_head, elems_packname, elems_data, picturl): cur = conn.cursor() # 既にデータベース登録済みのカード名はデータベースに登録しない duplicate = cur.execute('SELECT * FROM cardlist\ ~中略~ # データベースにないカードのみ、データベースに登録し、画像を保存する if duplicate.fetchone() is None: sql = 'INSERT INTO cardlist (cardname, ~中略~ if len(elems_data) == 11: data = (elems_head[0].text, elems_packname[0].text, picturl, ~中略~) else: data = (elems_head[0].text, elems_packname[0].text, picturl, ~中略~) cur.execute(sql, data) conn.commit() filename = os.path.basename(picturl) response = requests.get(picturl) image = response.content with open(filename, "wb") as cardpict: cardpict.write(image) def find_card_information(conn,driver,cardlink,listcards): for i in range(len(cardlink)): if len(cardlink) != 0: detail_info = ('https://dm.takaratomy.co.jp'+ cardlink[i].attrs['data-href']) driver.get(detail_info) time.sleep(5) soup = BeautifulSoup(driver.page_source, 'html.parser') elems = soup.find_all('table') cards = elems[0].find_all(src=re.compile('/wp-content/card')) for j in range (len(elems)): elems_head = elems[j].find_all('th') elems_packname = elems[j].find_all('span') elems_data = elems[j].find_all('td') if not cards: picturl = ('https://dm.takaratomy.co.jp' + listcards[i].attrs['src']) else: picturl = ('https://dm.takaratomy.co.jp' + cards[0].attrs['src']) if len(elems) == len(cards): picturl = ('https://dm.takaratomy.co.jp' + cards[j].attrs['src']) update_database(conn, elems_head, elems_packname, elems_data, picturl) def btn_click_lastpage(): driver_path = r'C:\chromedriver.exe' service = Service(executable_path=driver_path) driver = webdriver.Chrome(service=service) time.sleep(5) url = 'https://dm.takaratomy.co.jp/card/' driver.get(url) soup = BeautifulSoup(driver.page_source, 'html.parser') lastpagebtn = soup.find_all(class_='nextpostslink') lastpage = lastpagebtn[0].attrs['data-page'] time.sleep(5) driver.close() lastpage_data.delete(0, tk.END) lastpage_data.insert(tk.END,lastpage) def btn_click_generate(): startpage = startpage_data.get() tgtpage = tgtpage_data.get() lastpage = lastpage_data.get() if startpage == '': startpage = '1' ~中略~ if (int(startpage) + int(tgtpage)) >= int(lastpage): messagebox.showerror('ページ数指定エラー', '最終ページは' + lastpage + 'です。開始ページと取得ページ数を見直してください。') else: url = ['https://dm.takaratomy.co.jp/card/?v=%7B%22suggest%22:%22on%22,\ %22keyword_type%22:%5B%22card_name%22,%22card_ruby%22,\ %22card_text%22%5D,%22culture_cond%22:%5B%22%E5%8D%98%E8%89%B2%22,\ %22%E5%A4%9A%E8%89%B2%22%5D,%22pagenum%22:%22{}%22,\ %22samename%22:%22show%22,%22sort%22:%22release_new%22%7D' .format(i + int(startpage)) for i in range(int(tgtpage))] for i in range (len(url)): conn = sqlite3.connect('Duelmasters.db') driver_path = r"C:\chromedriver.exe" service = Service(executable_path=driver_path) driver = webdriver.Chrome(service=service) time.sleep(5) driver.get(url[i]) time.sleep(5) ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH) ctx.options |= 0x4 soup = BeautifulSoup(driver.page_source, 'html.parser') cardlink = soup.find_all(class_='cardImage') listcards = soup.find_all(src=re.compile('/wp-content/card')) find_card_information(conn,driver,cardlink,listcards) conn.close() driver.close() root = tk.Tk() root.geometry('400x300') root.title('Duel Masters database generator')
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
https://stackoverflow.com/questions/71603314/ssl-error-unsafe-legacy-renegotiation-disabled
補足
特になし
### 試したこと・調べたこと - [ ] teratailやGoogle等で検索した - [ ] ソースコードを自分なりに変更した - [ ] 知人に聞いた - [x] その他 ##### 上記の詳細・結果 https://stackoverflow.com/questions/71603314/ssl-error-unsafe-legacy-renegotiation-disabled ### 補足 特になし
該当のソースコードが「特になし」となっていますがどういうことでしょうか?SSLErrorは何かしらコードを実行した結果発生したものではないということでしょうか?
ソースコードを記載しました。文字数制限により一部中略表記となっております。
・質問のコードは今までは動いていて、突然エラーが発生するようになったのでしょうか?
・ブラウザでは該当のurlは見られるのでしょうか?
・質問のコードは今までは動いていて、突然エラーが発生するようになったのでしょうか?
今まで動いていた…とかではなく、プログラムは正常に動作するのですが、途中でコチラのエラーが発生しています。
Chromeでページ開く→次のページ開く…を繰り返すのですが、途中でコチラのエラーが出てきます。どうやら初めてアクセスするページで発生するようです。
・ブラウザでは該当のurlは見られるのでしょうか?
見れます!
「上記の詳細・結果」で参照している Stack Overflow の回答に回避策が書かれていますので、その通りに対処すればよいかと。
具体的にどの部分を実施すればよいでしょうか?
以下の回答の、
https://stackoverflow.com/a/72245418
> Create a custom openssl.cnf file in any directory with these contents:
以降です。
ありがとうございます!
カスタムのopenssl.cnfを作成することは分かりましたが、作成したopenssl.cnfをコード実行時に有効にするやり方が分かりません。上記リンクには下記のような文言がありましたが、"OPENSSL_CONF=/path/to/custom/openssl.cnf python your_scraper.py"をpythonのコードの最初の方に挿入すればよいのでしょうか?opensslをインストールしてpathにbinを設定していますが、実際opensslの指定(?)となると調べても出てきませんでした。お手数ですが、ご意見いただけないでしょうか。
Before running your program, make sure your OPENSSL_CONF environment variable is set to your custom openssl.cnf full path when running the scraper like so:
回答に投稿しました。ご確認ください。
回答1件
あなたの回答
tips
プレビュー