Pythonで自動処理するとエラーでクラッシュする

実現したいこと

サイトに自動ログインして特定の処理を行いたいです。

発生している問題・分からないこと

接続エラーが発生します。

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 203, in _new_conn sock = connection.create_connection( File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 85, in create_connection raise err File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 73, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 61] Connection refused The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 790, in urlopen response = self._make_request( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496, in _make_request conn.request( File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 395, in request self.endheaders() File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1248, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1008, in _send_output self.send(msg) File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 948, in send self.connect() File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 243, in connect self.sock = self._new_conn() File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 218, in _new_conn raise NewConnectionError( urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x10b687400>: Failed to establish a new connection: [Errno 61] Connection refused The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/............./login.py", line 138, in <module> browser.find_element(By.ID, "memoText").send_keys(word) File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 741, in find_element return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"] File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 345, in execute response = self.command_executor.execute(driver_command, params) File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/remote_connection.py", line 302, in execute return self._request(command_info[0], url, body=data) File "/usr/local/lib/python3.9/site-packages/selenium/webdriver/remote/remote_connection.py", line 322, in _request response = self._conn.request(method, url, body=body, headers=headers) File "/usr/local/lib/python3.9/site-packages/urllib3/_request_methods.py", line 118, in request return self.request_encode_body( File "/usr/local/lib/python3.9/site-packages/urllib3/_request_methods.py", line 217, in request_encode_body return self.urlopen(method, url, **extra_kw) File "/usr/local/lib/python3.9/site-packages/urllib3/poolmanager.py", line 444, in urlopen response = conn.urlopen(method, u.request_uri, **kw) File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 874, in urlopen return self.urlopen( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 874, in urlopen return self.urlopen( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 874, in urlopen return self.urlopen( File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 844, in urlopen retries = retries.increment( File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=58720): Max retries exceeded with url: /session/...../element (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10b687400>: Failed to establish a new connection: [Errno 61] Connection refused'))

該当のソースコード

Python

1import time 2import chromedriver_binary 3from selenium import webdriver 4from selenium.webdriver.common.by import By 5from selenium.webdriver.chrome import service 6 7#WEBブラウザの起動8driver = webdriver.Chrome() 9 10#自動ログインしたいウェブサイトのURLをコピペ11driver.get('https://hms.hc.nagasaki-u.ac.jp/menulogin.php') 12 13#ウェブサイトの起動を確認するため14time.sleep(1)15 16#例を参照して、属性name,classの値を入力17my_id = driver.find_element(By.NAME, "UID")18password = driver.find_element(By.NAME, "PW")19submit = driver.find_element(By.CLASS_NAME, "btn_style1")20 21#入力欄を空にする22my_id.clear()23password.clear()24 25#自動入力したIDとパスワードを入力26my_id.send_keys("自分のID")27password.send_keys("自分が設定したパスワード")28 29#ログインボタンを自動入力30submit.click()31 32#ログインの確認のための5秒停止33time.sleep(5)34 35#ブラウザを閉じる36driver.close()37

試したこと・調べたこと

上記の詳細・結果

上記のようなコードを実行すると接続エラーが返ってきます。
Python初心者のため原因と対処方法が全くわかりません。

お手柔らかにお願いいたします。

補足

特になし

コメントを投稿

0 コメント