質問編集履歴

2

意図的に内容を抹消する行為にあたるため

2021/08/02 02:50

投稿

tompooh
tompooh

スコア6

test CHANGED
@@ -1 +1 @@
1
- xxxxxxxxxxxx
1
+ URLError: <urlopen error [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。>を解決したい
test CHANGED
@@ -1 +1,195 @@
1
+ ### 前提・実現したいこと
2
+
3
+ htmlを取得したく、例えばこのようにすると
4
+
5
+ url = 'https://www.google.com/'
6
+
7
+ res = req.urlopen(url)
8
+
9
+ 以下のエラーメッセージが出ます。
10
+
11
+ URLError: <urlopen error [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。>を解決したい
12
+
13
+ ---------------------------------------------------------------------------
14
+
15
+ ConnectionResetError Traceback (most recent call last)
16
+
17
+ ~\Anaconda3\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
18
+
19
+ 1349 try:
20
+
21
+ -> 1350 h.request(req.get_method(), req.selector, req.data, headers,
22
+
23
+ 1351 encode_chunked=req.has_header('Transfer-encoding'))
24
+
25
+ ~\Anaconda3\lib\http\client.py in request(self, method, url, body, headers, encode_chunked)
26
+
27
+ 1254 """Send a complete request to the server."""
28
+
29
+ -> 1255 self._send_request(method, url, body, headers, encode_chunked)
30
+
31
+ 1256
32
+
33
+ ~\Anaconda3\lib\http\client.py in _send_request(self, method, url, body, headers, encode_chunked)
34
+
35
+ 1300 body = _encode(body, 'body')
36
+
37
+ -> 1301 self.endheaders(body, encode_chunked=encode_chunked)
38
+
39
+ 1302
40
+
41
+ ~\Anaconda3\lib\http\client.py in endheaders(self, message_body, encode_chunked)
42
+
43
+ 1249 raise CannotSendHeader()
44
+
45
+ -> 1250 self._send_output(message_body, encode_chunked=encode_chunked)
46
+
47
+ 1251
48
+
49
+ ~\Anaconda3\lib\http\client.py in _send_output(self, message_body, encode_chunked)
50
+
51
+ 1009 del self._buffer[:]
52
+
53
+ -> 1010 self.send(msg)
54
+
55
+ 1011
56
+
57
+ ~\Anaconda3\lib\http\client.py in send(self, data)
58
+
59
+ 949 if self.auto_open:
60
+
61
+ --> 950 self.connect()
62
+
63
+ 951 else:
64
+
65
+ ~\Anaconda3\lib\http\client.py in connect(self)
66
+
67
+ 1423
68
+
69
+ -> 1424 self.sock = self._context.wrap_socket(self.sock,
70
+
71
+ 1425 server_hostname=server_hostname)
72
+
73
+ ~\Anaconda3\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
74
+
75
+ 499 # ctx._wrap_socket()
76
+
77
+ --> 500 return self.sslsocket_class._create(
78
+
79
+ 501 sock=sock,
80
+
81
+ ~\Anaconda3\lib\ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
82
+
83
+ 1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
84
+
85
+ -> 1040 self.do_handshake()
86
+
87
+ 1041 except (OSError, ValueError):
88
+
89
+ ~\Anaconda3\lib\ssl.py in do_handshake(self, block)
90
+
91
+ 1308 self.settimeout(None)
92
+
93
+ -> 1309 self._sslobj.do_handshake()
94
+
95
+ 1310 finally:
96
+
97
+ ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。
98
+
99
+ During handling of the above exception, another exception occurred:
100
+
101
+ URLError Traceback (most recent call last)
102
+
103
+ <ipython-input-11-a0860de31a6c> in <module>
104
+
105
+ 1 url = 'https://www.google.com/'
106
+
107
+ 2
108
+
109
+ ----> 3 res = req.urlopen(url)
110
+
111
+ 4 #soup = BeautifulSoup(res, "html.parser")
112
+
113
+ 5 #result = soup.select("a[href]")
114
+
115
+ ~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
116
+
117
+ 220 else:
118
+
119
+ 221 opener = _opener
120
+
121
+ --> 222 return opener.open(url, data, timeout)
122
+
123
+ 223
124
+
125
+ 224 def install_opener(opener):
126
+
127
+ ~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
128
+
129
+ 523
130
+
131
+ 524 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
132
+
133
+ --> 525 response = self._open(req, data)
134
+
135
+ 526
136
+
137
+ 527 # post-process response
138
+
139
+ ~\Anaconda3\lib\urllib\request.py in _open(self, req, data)
140
+
141
+ 540
142
+
143
+ 541 protocol = req.type
144
+
145
+ --> 542 result = self._call_chain(self.handle_open, protocol, protocol +
146
+
147
+ 543 '_open', req)
148
+
149
+ 544 if result:
150
+
151
+ ~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
152
+
153
+ 500 for handler in handlers:
154
+
155
+ 501 func = getattr(handler, meth_name)
156
+
157
+ --> 502 result = func(*args)
158
+
159
+ 503 if result is not None:
160
+
161
+ 504 return result
162
+
163
+ ~\Anaconda3\lib\urllib\request.py in https_open(self, req)
164
+
165
+ 1391
166
+
167
+ 1392 def https_open(self, req):
168
+
169
+ -> 1393 return self.do_open(http.client.HTTPSConnection, req,
170
+
1
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
171
+ 1394 context=self._context, check_hostname=self._check_hostname)
172
+
173
+ 1395
174
+
175
+ ~\Anaconda3\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
176
+
177
+ 1351 encode_chunked=req.has_header('Transfer-encoding'))
178
+
179
+ 1352 except OSError as err: # timeout error
180
+
181
+ -> 1353 raise URLError(err)
182
+
183
+ 1354 r = h.getresponse()
184
+
185
+ 1355 except:
186
+
187
+ URLError: <urlopen error [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。>
188
+
189
+ ### 補足情報(FW/ツールのバージョンなど)
190
+
191
+ 今までは問題なくできていたのですが、数カ月ぶりに使おうとしたらエラーが表示されて使えなくなりました。
192
+
193
+ 試しに別のPCで同様のコードで試みたところ問題なく実行できました。
194
+
195
+ これはPCの問題なのでしょうか。

1

xxxxxxxxxxxxxxxxxxxxxx

2021/08/02 02:50

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- URLError: <urlopen error [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。>を解決したい
1
+ xxxxxxxxxxxx
test CHANGED
@@ -1,243 +1 @@
1
- ### 前提・実現したいこと
2
-
3
- htmlを取得したく、例えばこのようにすると
4
-
5
- url = 'https://www.google.com/'
6
-
7
- res = req.urlopen(url)
8
-
9
-
10
-
11
- 以下のエラーメッセージが出ます。
12
-
13
- URLError: <urlopen error [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。>を解決したい
14
-
15
-
16
-
17
- ---------------------------------------------------------------------------
18
-
19
- ConnectionResetError Traceback (most recent call last)
20
-
21
- ~\Anaconda3\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
22
-
23
- 1349 try:
24
-
25
- -> 1350 h.request(req.get_method(), req.selector, req.data, headers,
26
-
27
- 1351 encode_chunked=req.has_header('Transfer-encoding'))
28
-
29
-
30
-
31
- ~\Anaconda3\lib\http\client.py in request(self, method, url, body, headers, encode_chunked)
32
-
33
- 1254 """Send a complete request to the server."""
34
-
35
- -> 1255 self._send_request(method, url, body, headers, encode_chunked)
36
-
37
- 1256
38
-
39
-
40
-
41
- ~\Anaconda3\lib\http\client.py in _send_request(self, method, url, body, headers, encode_chunked)
42
-
43
- 1300 body = _encode(body, 'body')
44
-
45
- -> 1301 self.endheaders(body, encode_chunked=encode_chunked)
46
-
47
- 1302
48
-
49
-
50
-
51
- ~\Anaconda3\lib\http\client.py in endheaders(self, message_body, encode_chunked)
52
-
53
- 1249 raise CannotSendHeader()
54
-
55
- -> 1250 self._send_output(message_body, encode_chunked=encode_chunked)
56
-
57
- 1251
58
-
59
-
60
-
61
- ~\Anaconda3\lib\http\client.py in _send_output(self, message_body, encode_chunked)
62
-
63
- 1009 del self._buffer[:]
64
-
65
- -> 1010 self.send(msg)
66
-
67
- 1011
68
-
69
-
70
-
71
- ~\Anaconda3\lib\http\client.py in send(self, data)
72
-
73
- 949 if self.auto_open:
74
-
75
- --> 950 self.connect()
76
-
77
- 951 else:
78
-
79
-
80
-
81
- ~\Anaconda3\lib\http\client.py in connect(self)
82
-
83
- 1423
84
-
85
- -> 1424 self.sock = self._context.wrap_socket(self.sock,
86
-
87
- 1425 server_hostname=server_hostname)
88
-
89
-
90
-
91
- ~\Anaconda3\lib\ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
92
-
93
- 499 # ctx._wrap_socket()
94
-
95
- --> 500 return self.sslsocket_class._create(
96
-
97
- 501 sock=sock,
98
-
99
-
100
-
101
- ~\Anaconda3\lib\ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
102
-
103
- 1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
104
-
105
- -> 1040 self.do_handshake()
106
-
107
- 1041 except (OSError, ValueError):
108
-
109
-
110
-
111
- ~\Anaconda3\lib\ssl.py in do_handshake(self, block)
112
-
113
- 1308 self.settimeout(None)
114
-
115
- -> 1309 self._sslobj.do_handshake()
116
-
117
- 1310 finally:
118
-
119
-
120
-
121
- ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。
122
-
123
-
124
-
125
- During handling of the above exception, another exception occurred:
126
-
127
-
128
-
129
- URLError Traceback (most recent call last)
130
-
131
- <ipython-input-11-a0860de31a6c> in <module>
132
-
133
- 1 url = 'https://www.google.com/'
134
-
135
- 2
136
-
137
- ----> 3 res = req.urlopen(url)
138
-
139
- 4 #soup = BeautifulSoup(res, "html.parser")
140
-
141
- 5 #result = soup.select("a[href]")
142
-
143
-
144
-
145
- ~\Anaconda3\lib\urllib\request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
146
-
147
- 220 else:
148
-
149
- 221 opener = _opener
150
-
151
- --> 222 return opener.open(url, data, timeout)
152
-
153
- 223
154
-
155
- 224 def install_opener(opener):
156
-
157
-
158
-
159
- ~\Anaconda3\lib\urllib\request.py in open(self, fullurl, data, timeout)
160
-
161
- 523
162
-
163
- 524 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
164
-
165
- --> 525 response = self._open(req, data)
166
-
167
- 526
168
-
169
- 527 # post-process response
170
-
171
-
172
-
173
- ~\Anaconda3\lib\urllib\request.py in _open(self, req, data)
174
-
175
- 540
176
-
177
- 541 protocol = req.type
178
-
179
- --> 542 result = self._call_chain(self.handle_open, protocol, protocol +
180
-
181
- 543 '_open', req)
182
-
183
- 544 if result:
184
-
185
-
186
-
187
- ~\Anaconda3\lib\urllib\request.py in _call_chain(self, chain, kind, meth_name, *args)
188
-
189
- 500 for handler in handlers:
190
-
191
- 501 func = getattr(handler, meth_name)
192
-
193
- --> 502 result = func(*args)
194
-
195
- 503 if result is not None:
196
-
197
- 504 return result
198
-
199
-
200
-
201
- ~\Anaconda3\lib\urllib\request.py in https_open(self, req)
202
-
203
- 1391
204
-
205
- 1392 def https_open(self, req):
206
-
207
- -> 1393 return self.do_open(http.client.HTTPSConnection, req,
208
-
209
- 1394 context=self._context, check_hostname=self._check_hostname)
1
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
210
-
211
- 1395
212
-
213
-
214
-
215
- ~\Anaconda3\lib\urllib\request.py in do_open(self, http_class, req, **http_conn_args)
216
-
217
- 1351 encode_chunked=req.has_header('Transfer-encoding'))
218
-
219
- 1352 except OSError as err: # timeout error
220
-
221
- -> 1353 raise URLError(err)
222
-
223
- 1354 r = h.getresponse()
224
-
225
- 1355 except:
226
-
227
-
228
-
229
- URLError: <urlopen error [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。>
230
-
231
-
232
-
233
-
234
-
235
- ### 補足情報(FW/ツールのバージョンなど)
236
-
237
-
238
-
239
- 今までは問題なくできていたのですが、数カ月ぶりに使おうとしたらエラーが表示されて使えなくなりました。
240
-
241
- 試しに別のPCで同様のコードで試みたところ問題なく実行できました。
242
-
243
- これはPCの問題なのでしょうか。