我是一名学习python的学生,并且正在从网页中提取信息。如果我尝试运行从实时地震记录中获取信息的程序,则会收到SSL错误(更多详细信息,请参见下面的内容。)我所知道的代码没有错误,因为我正在跟老师一起在在线课程。
我尝试同时运行“安装证书”命令和“更新外壳程序配置文件”命令,但均不起作用。我正在Visual Studio代码中用python 3.7.2进行编码,我也在Mac上。我得到的错误代码是:
Exception has occurred: URLError
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1319, in do_open
raise URLError(err)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 1360, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 543, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 755, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 503, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 563, in error
result = self._call_chain(*args)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 531, in open
response = meth(req, response)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 222, in urlopen
我在终端中也收到了此消息:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/certifi-2019.3.9.dist-info'
Consider using the `--user` option or check the permissions.
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command
我尝试在终端中键入该命令,但显示未找到命令。我正在使用学校计算机,因此某些事情被阻止了,也许这是问题的一部分,我不太清楚。这是我的代码:
import urllib.request
import json
def printResults(data):
theJSON = json.loads(data)
if "title" in theJSON["metadata"]:
print(theJSON["metadata"]["title"])
count = theJSON["metadata"]["count"]
print (str(count) + " events recorded")
def main():
urlData = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_day.geojson"
webUrl = urllib.request.urlopen(urlData)
print ("result code: " + str(webUrl.getcode()))
if (webUrl.getcode() == 200):
data = webUrl.read()
printResults(data)
else:
print("Received error, cannot parse results")
if __name__ == "__main__":
main()
如果有解决方案,请记住我是计算机科学第一学期的学生,所以请简单地解释一下。