質問編集履歴

2

エラー文修正

2021/03/02 10:27

投稿

nogish
nogish

スコア20

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ```Jupyterlab
10
10
 
11
- URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)>
11
+ URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)>
12
12
 
13
13
  ```
14
14
 

1

pythonコード、エラー文、サイト情報の追加

2021/03/02 10:27

投稿

nogish
nogish

スコア20

test CHANGED
File without changes
test CHANGED
@@ -30,17 +30,245 @@
30
30
 
31
31
 
32
32
 
33
+ ```Jupyterlab
34
+
35
+ ---------------------------------------------------------------------------
36
+
37
+ SSLCertVerificationError Traceback (most recent call last)
38
+
39
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
40
+
41
+ 1345 try:
42
+
43
+ -> 1346 h.request(req.get_method(), req.selector, req.data, headers,
44
+
45
+ 1347 encode_chunked=req.has_header('Transfer-encoding'))
46
+
47
+
48
+
49
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py in request(self, method, url, body, headers, encode_chunked)
50
+
51
+ 1254 """Send a complete request to the server."""
52
+
53
+ -> 1255 self._send_request(method, url, body, headers, encode_chunked)
54
+
55
+ 1256
56
+
57
+
58
+
59
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py in _send_request(self, method, url, body, headers, encode_chunked)
60
+
61
+ 1300 body = _encode(body, 'body')
62
+
63
+ -> 1301 self.endheaders(body, encode_chunked=encode_chunked)
64
+
65
+ 1302
66
+
67
+
68
+
69
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py in endheaders(self, message_body, encode_chunked)
70
+
71
+ 1249 raise CannotSendHeader()
72
+
73
+ -> 1250 self._send_output(message_body, encode_chunked=encode_chunked)
74
+
75
+ 1251
76
+
77
+
78
+
79
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py in _send_output(self, message_body, encode_chunked)
80
+
81
+ 1009 del self._buffer[:]
82
+
83
+ -> 1010 self.send(msg)
84
+
85
+ 1011
86
+
87
+
88
+
89
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py in send(self, data)
90
+
91
+ 949 if self.auto_open:
92
+
93
+ --> 950 self.connect()
94
+
95
+ 951 else:
96
+
97
+
98
+
99
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py in connect(self)
100
+
101
+ 1423
102
+
103
+ -> 1424 self.sock = self._context.wrap_socket(self.sock,
104
+
105
+ 1425 server_hostname=server_hostname)
106
+
107
+
108
+
109
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, session)
110
+
111
+ 499 # ctx._wrap_socket()
112
+
113
+ --> 500 return self.sslsocket_class._create(
114
+
115
+ 501 sock=sock,
116
+
117
+
118
+
119
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py in _create(cls, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname, context, session)
120
+
121
+ 1039 raise ValueError("do_handshake_on_connect should not be specified for non-blocking sockets")
122
+
123
+ -> 1040 self.do_handshake()
124
+
125
+ 1041 except (OSError, ValueError):
126
+
127
+
128
+
129
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py in do_handshake(self, block)
130
+
131
+ 1308 self.settimeout(None)
132
+
133
+ -> 1309 self._sslobj.do_handshake()
134
+
135
+ 1310 finally:
136
+
137
+
138
+
139
+ SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)
140
+
141
+
142
+
143
+ During handling of the above exception, another exception occurred:
144
+
145
+
146
+
147
+ URLError Traceback (most recent call last)
148
+
149
+ <ipython-input-7-81afa538059d> in <module>
150
+
151
+ 1 url = 'https://scraping-for-beginner.herokuapp.com/ranking/'
152
+
153
+ ----> 2 response = req.urlopen(url) # 指定したwebサイトのHTMLを取得できる関数
154
+
155
+
156
+
157
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
158
+
159
+ 212 else:
160
+
161
+ 213 opener = _opener
162
+
163
+ --> 214 return opener.open(url, data, timeout)
164
+
165
+ 215
166
+
167
+ 216 def install_opener(opener):
168
+
169
+
170
+
171
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in open(self, fullurl, data, timeout)
172
+
173
+ 515
174
+
175
+ 516 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
176
+
177
+ --> 517 response = self._open(req, data)
178
+
179
+ 518
180
+
181
+ 519 # post-process response
182
+
183
+
184
+
185
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in _open(self, req, data)
186
+
187
+ 532
188
+
189
+ 533 protocol = req.type
190
+
191
+ --> 534 result = self._call_chain(self.handle_open, protocol, protocol +
192
+
193
+ 535 '_open', req)
194
+
195
+ 536 if result:
196
+
197
+
198
+
199
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
200
+
201
+ 492 for handler in handlers:
202
+
203
+ 493 func = getattr(handler, meth_name)
204
+
205
+ --> 494 result = func(*args)
206
+
207
+ 495 if result is not None:
208
+
209
+ 496 return result
210
+
211
+
212
+
213
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in https_open(self, req)
214
+
215
+ 1387
216
+
217
+ 1388 def https_open(self, req):
218
+
219
+ -> 1389 return self.do_open(http.client.HTTPSConnection, req,
220
+
221
+ 1390 context=self._context, check_hostname=self._check_hostname)
222
+
223
+ 1391
224
+
225
+
226
+
227
+ /usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/urllib/request.py in do_open(self, http_class, req, **http_conn_args)
228
+
229
+ 1347 encode_chunked=req.has_header('Transfer-encoding'))
230
+
231
+ 1348 except OSError as err: # timeout error
232
+
233
+ -> 1349 raise URLError(err)
234
+
235
+ 1350 r = h.getresponse()
236
+
237
+ 1351 except:
238
+
239
+
240
+
241
+ URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1123)>
242
+
243
+ ```
244
+
33
245
  ```terminal
34
246
 
35
247
  -bash: /Applications/Python 3.9/Install Certificates.command: No such file or directory
36
248
 
37
249
  ```
38
250
 
39
-
40
-
41
251
  ### 該当のソースコード
42
252
 
253
+ ```Jupyterlab
254
+
255
+ !pip3 install beautifulsoup4
256
+
257
+
258
+
259
+ from bs4 import BeautifulSoup
260
+
261
+ import urllib.request as req
262
+
263
+
264
+
265
+ url = 'https://scraping-for-beginner.herokuapp.com/ranking/'
266
+
267
+ response = req.urlopen(url)
268
+
269
+ ```
270
+
43
- 何を変えればよいかわからず、とりあえずバージョンの数字だけ自分のpyhtonのバージョンに合わせました
271
+ certifiモジュールの方は、何を変えればよいかわからず、とりあえずバージョンの数字だけ自分のpyhtonのバージョンに合わせました
44
272
 
45
273
 
46
274