Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python上使用Google搜索API时出错_Python_Python 3.x_Google Search Api - Fatal编程技术网

在Python上使用Google搜索API时出错

在Python上使用Google搜索API时出错,python,python-3.x,google-search-api,Python,Python 3.x,Google Search Api,我正在尝试在Python上运行Google搜索API,特别是这一个: 当我试图通过在Sublime Text 3上运行此代码来测试它时 从谷歌导入谷歌 num_page=1 search\u results=google.search(“这是我的查询”,num\u页面) 对于搜索结果中的结果: 打印(结果说明) 我得到了很多错误,如下所示 Traceback (most recent call last): File "/Library/Frameworks/Python.framewor

我正在尝试在Python上运行Google搜索API,特别是这一个:

当我试图通过在Sublime Text 3上运行此代码来测试它时

从谷歌导入谷歌
num_page=1
search\u results=google.search(“这是我的查询”,num\u页面)
对于搜索结果中的结果:
打印(结果说明)
我得到了很多错误,如下所示

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 67, in get
    context=context,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 154, in load
    for item in get_browsers(verify_ssl=verify_ssl):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 97, in get_browsers
    html = get(settings.BROWSERS_STATS_PAGE, verify_ssl=verify_ssl)
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 84, in get
    raise FakeUserAgentError('Maximum amount of retries reached')
fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 67, in get
    context=context,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 154, in load
    for item in get_browsers(verify_ssl=verify_ssl):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 97, in get_browsers
    html = get(settings.BROWSERS_STATS_PAGE, verify_ssl=verify_ssl)
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 84, in get
    raise FakeUserAgentError('Maximum amount of retries reached')
fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1318, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1400, in connect
    server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 407, in wrap_socket
    _context=self, _session=session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 814, in __init__
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1068, in do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 689, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 67, in get
    context=context,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
    response = self._open(req, data)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
    '_open', req)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1320, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777)>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myname/Library/Application Support/Sublime Text 3/Packages/User/first.py", line 7, in <module>
    search_results = google.search("This is my query", num_page)
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/google/modules/standard_search.py", line 70, in search
    html = get_html(url)
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/google/modules/utils.py", line 432, in get_html
    ua = UserAgent()
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/fake.py", line 69, in __init__
    self.load()
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/fake.py", line 78, in load
    verify_ssl=self.verify_ssl,
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 250, in load_cached
    update(path, use_cache_server=use_cache_server, verify_ssl=verify_ssl)
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 245, in update
    write(path, load(use_cache_server=use_cache_server, verify_ssl=verify_ssl))
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 189, in load
    verify_ssl=verify_ssl,
  File "/Users/myname/Library/Python/3.6/lib/python/site-packages/fake_useragent/utils.py", line 84, in get
    raise FakeUserAgentError('Maximum amount of retries reached')
fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached

回溯(最近一次呼叫最后一次):
dou open中的文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第1318行
encode_chunked=req.has_头('Transfer-encoding'))
请求中的文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1239行
self.\u发送\u请求(方法、url、正文、标题、编码\u分块)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1285行,在发送请求中
self.endheaders(body,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1234行,在endheaders中
self.\u发送\u输出(消息体,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1026行,在发送输出中
self.send(msg)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第964行,在send中
self.connect()
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1400行,在connect中
服务器\主机名=服务器\主机名)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第407行,在wrap_套接字中
_上下文=自身,_会话=会话)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第814行,在__
self.do_握手
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第1068行,在do_握手中
赛尔夫:握手
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第689行,在do_握手中
赛尔夫:握手
ssl.SSLError:[ssl:CERTIFICATE\u VERIFY\u FAILED]证书验证失败(\u ssl.c:777)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/myname/Library/Python/3.6/lib/Python/site packages/fake_useragent/utils.py”,get中第67行
上下文=上下文,
urlopen中的文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第223行
返回opener.open(url、数据、超时)
打开文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第526行
响应=自身打开(请求,数据)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第544行,打开
"开放",
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第504行,在调用链中
结果=func(*args)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第1361行,https_open
上下文=self.\u上下文,检查主机名=self.\u检查主机名)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第1320行,打开
引发URL错误(err)
urllib.error.urleror:
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/myname/Library/Python/3.6/lib/Python/site packages/fake_useragent/utils.py”,第154行,加载
对于get\u浏览器中的项(验证\u ssl=验证\u ssl):
get_浏览器中的文件“/Users/myname/Library/Python/3.6/lib/Python/site packages/fake_useragent/utils.py”,第97行
html=get(settings.BROWSERS\u STATS\u页面,verify\u ssl=verify\u ssl)
文件“/Users/myname/Library/Python/3.6/lib/Python/site-packages/fake_-useragent/utils.py”,get第84行
引发FakeUserAgentError('已达到最大重试次数')
fake_useragent.errors.FakeUserAgentError:已达到最大重试次数
回溯(最近一次呼叫最后一次):
dou open中的文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py”,第1318行
encode_chunked=req.has_头('Transfer-encoding'))
请求中的文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1239行
self.\u发送\u请求(方法、url、正文、标题、编码\u分块)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1285行,在发送请求中
self.endheaders(body,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1234行,在endheaders中
self.\u发送\u输出(消息体,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1026行,在发送输出中
self.send(msg)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第964行,在send中
self.connect()
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1400行,在connect中
服务器\主机名=服务器\主机名)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第407行,在wrap_套接字中
_上下文=自身,_会话=会话)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第814行,在__
self.do_握手
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第1068行,在do_握手中
赛尔夫:握手
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py”,第689行,在do_握手中
赛尔夫:握手
ssl.SSLError:[ssl:CERTIFICATE\u VERIFY\u FAILED]证书验证失败(\u ssl.c:777)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/Users/myname/Library/Python/3.6/lib/pyth