Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.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 无法在www.googleapis.com上找到服务器_Python - Fatal编程技术网

Python 无法在www.googleapis.com上找到服务器

Python 无法在www.googleapis.com上找到服务器,python,Python,我想用谷歌客户端API提取数据 我已完成的步骤: 创建了google自定义搜索引擎并具有搜索引擎id 在项目下创建了一个搜索API(在我的谷歌云中) 我正在使用以下代码段: my_api_key = "my_API_KEY" my_cse_id = "my_CSE ID" def google_search(search_term, api_key, cse_id, **kwargs): service = build("customs

我想用谷歌客户端API提取数据

我已完成的步骤:

  • 创建了google自定义搜索引擎并具有搜索引擎id
  • 在项目下创建了一个搜索API(在我的谷歌云中)
  • 我正在使用以下代码段:

    my_api_key = "my_API_KEY"
    my_cse_id = "my_CSE ID"
    
    def google_search(search_term, api_key, cse_id, **kwargs):
        service = build("customsearch", "v1", developerKey=api_key, cache_discovery=False)
        res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
        return res['items']
    
    results = google_search('yoga', my_api_key, my_cse_id, num=10)
    print(results)
    
    也指此线程:

    我正在获取请求的URL:

    2020-11-07 15:25:54,336 | INFO | discovery.py:272 | _retrieve_discovery_doc | URL being requested: GET https://www.googleapis.com/discovery/v1/apis/customsearch/v1/rest?key=
    
    问题

    gaierror                                  Traceback (most recent call last)
    /opt/conda/lib/python3.6/site-packages/httplib2/__init__.py in _conn_request(self, conn, request_uri, method, body, headers)
       1500                 if conn.sock is None:
    -> 1501                     conn.connect()
       1502                 conn.request(method, request_uri, body, headers)
    
    /opt/conda/lib/python3.6/site-packages/httplib2/__init__.py in connect(self)
       1269 
    -> 1270         address_info = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
       1271         for family, socktype, proto, canonname, sockaddr in address_info:
    
    /opt/conda/lib/python3.6/socket.py in getaddrinfo(host, port, family, type, proto, flags)
        744     addrlist = []
    --> 745     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
        746         af, socktype, proto, canonname, sa = res
    
    gaierror: [Errno -3] Temporary failure in name resolution
    
    During handling of the above exception, another exception occurred:
    
    ServerNotFoundError                       Traceback (most recent call last)
    <ipython-input-3-b59229e204c0> in <module>()
          9     return res['items']
         10 
    ---> 11 results = google_search('yoga', my_api_key, my_cse_id, num=10)
         12 results
    
    <ipython-input-3-b59229e204c0> in google_search(search_term, api_key, cse_id, **kwargs)
          5 
          6 def google_search(search_term, api_key, cse_id, **kwargs):
    ----> 7     service = build("customsearch", "v1", developerKey=api_key, cache_discovery=False)
          8     res = service.cse().list(q=search_term, cx=cse_id, **kwargs).execute()
          9     return res['items']
    
    /opt/conda/lib/python3.6/site-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
        128                 elif positional_parameters_enforcement == POSITIONAL_WARNING:
        129                     logger.warning(message)
    --> 130             return wrapped(*args, **kwargs)
        131         return positional_wrapper
        132 
    
    /opt/conda/lib/python3.6/site-packages/googleapiclient/discovery.py in build(serviceName, version, http, discoveryServiceUrl, developerKey, model, requestBuilder, credentials, cache_discovery, cache)
        222     try:
        223       content = _retrieve_discovery_doc(
    --> 224         requested_url, discovery_http, cache_discovery, cache, developerKey)
        225       return build_from_document(content, base=discovery_url, http=http,
        226           developerKey=developerKey, model=model, requestBuilder=requestBuilder,
    
    /opt/conda/lib/python3.6/site-packages/googleapiclient/discovery.py in _retrieve_discovery_doc(url, http, cache_discovery, cache, developerKey)
        272   logger.info('URL being requested: GET %s', actual_url)
        273 
    --> 274   resp, content = http.request(actual_url)
        275 
        276   if resp.status >= 400:
    
    /opt/conda/lib/python3.6/site-packages/httplib2/__init__.py in request(self, uri, method, body, headers, redirections, connection_type)
       1924                         headers,
       1925                         redirections,
    -> 1926                         cachekey,
       1927                     )
       1928         except Exception as e:
    
    /opt/conda/lib/python3.6/site-packages/httplib2/__init__.py in _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey)
       1593 
       1594         (response, content) = self._conn_request(
    -> 1595             conn, request_uri, method, body, headers
       1596         )
       1597 
    
    /opt/conda/lib/python3.6/site-packages/httplib2/__init__.py in _conn_request(self, conn, request_uri, method, body, headers)
       1506             except socket.gaierror:
       1507                 conn.close()
    -> 1508                 raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
       1509             except socket.error as e:
       1510                 errno_ = (
    
    ServerNotFoundError: Unable to find the server at www.googleapis.com
    
    GAI错误回溯(最近一次调用)
    /opt/conda/lib/python3.6/site packages/httplib2/\uuuuuu init\uuuuuuuuuu.py in\u conn\u请求(self、conn、请求uri、方法、正文、头)
    1500如果conn.sock为无:
    ->1501连接件()
    1502 conn.request(方法、请求uri、正文、标题)
    /opt/conda/lib/python3.6/site packages/httplib2/__init__;u.py in connect(self)
    1269
    ->1270 address\u info=socket.getaddrinfo(主机、端口、0、socket.SOCK\u流)
    1271系列、socktype、proto、canonname、地址中的sockaddr\u信息:
    /getaddrinfo中的opt/conda/lib/python3.6/socket.py(主机、端口、系列、类型、协议、标志)
    744 addrlist=[]
    -->745用于_socket.getaddrinfo(主机、端口、系列、类型、协议、标志)中的res:
    746 af,socktype,原型,佳能名称,sa=res
    gaierror:[Errno-3]名称解析暂时失败
    在处理上述异常期间,发生了另一个异常:
    ServerNotFoundError回溯(最近一次调用上次)
    在()
    9返回资源[“项目”]
    10
    --->11结果=谷歌搜索(“瑜伽”,我的api密钥,我的cse id,num=10)
    12结果
    在谷歌搜索中(搜索词、api键、cse id、**kwargs)
    5.
    6 def google_搜索(搜索词、api_键、cse_id、**kwargs):
    ---->7服务=构建(“customsearch”,“v1”,developerKey=api\U键,缓存\U发现=False)
    8 res=service.cse().list(q=search\u term,cx=cse\u id,**kwargs.execute())
    9返回资源[“项目”]
    /位置包装中的opt/conda/lib/python3.6/site-packages/googleapiclient//u helpers.py(*args,**kwargs)
    128 elif位置参数执行==位置警告:
    129.警告(信息)
    -->130包装退货(*args,**kwargs)
    131返回位置包装器
    132
    /内部版本中的opt/conda/lib/python3.6/site-packages/googleapiclient/discovery.py(serviceName、version、http、discoveryServiceUrl、developerKey、model、requestBuilder、凭证、缓存\发现、缓存)
    222尝试:
    223内容=\u检索\u发现\u文档(
    -->224请求的\u url、发现\u http、缓存\u发现、缓存、developerKey)
    225从文档返回构建(content,base=discovery\u url,http=http,
    226 developerKey=developerKey,model=model,requestBuilder=requestBuilder,
    /opt/conda/lib/python3.6/site-packages/googleapiclient/discovery.py in_retrieve_discovery_doc(url、http、缓存_discovery、缓存、developerKey)
    272 logger.info('请求的URL:获取%s',实际的\u URL)
    273
    -->274 resp,content=http.request(实际url)
    275
    276如果响应状态>=400:
    /请求中的opt/conda/lib/python3.6/site packages/httplib2/_init__uu.py(self、uri、方法、主体、头、重定向、连接类型)
    1924年,
    1925年重新定向,
    ->1926年的今天,
    1927                     )
    1928年例外情况除外,如e:
    /opt/conda/lib/python3.6/site packages/httplib2/__init__;u.py in_u请求(self、conn、host、绝对uri、请求uri、方法、正文、头、重定向、缓存键)
    1593
    1594(响应、内容)=自我连接请求(
    ->1595 conn,请求uri,方法,正文,标题
    1596         )
    1597
    /opt/conda/lib/python3.6/site packages/httplib2/\uuuuuu init\uuuuuuuuuu.py in\u conn\u请求(self、conn、请求uri、方法、正文、头)
    1506插座除外。错误:
    1507控制室关闭()
    ->1508 raise ServerNotFoundError(“在%s”%conn.host上找不到服务器)
    1509插座除外。错误为e:
    1510错误号=(
    ServerNotFoundError:无法在www.googleapis.com上找到服务器
    
    对于正常步骤,您应该先抓取一页,然后找到该页的项目

    在代码中,步骤不清楚。您设置了num=10,但没有调用它,也没有设置起始页

    # for example, get one page
    res = service.cse().list(q=keyword, cx=cse_id).execute()
    
    
    # find the next page
    next_res = service.cse().list(q=query_keywords, cx=cse_id, num=10, start=res['queries']['nextPage'][0]['startIndex'],).execute()
    
    

    希望它能解决我们的问题

    至于正常的步骤,你应该先抓取一个页面,然后找到该页面的项目

    在代码中,步骤不清楚。您设置了num=10,但没有调用它,也没有设置起始页

    # for example, get one page
    res = service.cse().list(q=keyword, cx=cse_id).execute()
    
    
    # find the next page
    next_res = service.cse().list(q=query_keywords, cx=cse_id, num=10, start=res['queries']['nextPage'][0]['startIndex'],).execute()
    
    

    希望它能解决我们的问题

    gaierro:[Errno-3]名称解析暂时失败
    检查您的internet连接、DNS设置、防火墙和路由设置。我在kaggle笔记本上这样做。我认为DNS和防火墙不会有问题,internet工作正常。
    gaierro:[Errno-3]名称解析暂时失败
    请检查您的internet连接、DNS设置、防火墙和路由设置。我正在kaggle笔记本上执行此操作。我认为DNS和防火墙不会出现问题,internet工作正常。