【问题标题】:httplib2.ServerNotFoundError: Unable to find the server at accounts.google.comhttplib2.ServerNotFoundError:无法在 accounts.google.com 上找到服务器
【发布时间】:2018-06-22 13:13:40
【问题描述】:

我已经为这个问题苦苦挣扎了一段时间,并且已经搜索了互联网,但仍然无法解决它。

我正在尝试运行 python 脚本以从我工作的本地机器访问 google 工作表(因此可能是防火墙问题)。每当我连接到访客网络时,脚本都可以正常工作。每当我尝试使用我的工作内部网络(有或没有代理设置)时,我都会收到以下错误:

***Traceback (most recent call last):
  File "C:\Python36-32\lib\site-packages\httplib2\__init__.py", line 995, in _conn_request
    conn.connect()
  File "C:\Python36-32\lib\http\client.py", line 1392, in connect
    super().connect()
  File "C:\Python36-32\lib\http\client.py", line 936, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "C:\Python36-32\lib\socket.py", line 704, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "C:\Python36-32\lib\socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.1\helpers\pydev\pydevd.py", line 1664, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.1\helpers\pydev\pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.1\helpers\pydev\pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Git/datalab-notebooks/2017-vin-profitability/US/Finance_Mapping_test.py", line 23, in <module>
    client = gspread.authorize(credentials)
  File "C:\Python36-32\lib\site-packages\gspread\__init__.py", line 38, in authorize
    client.login()
  File "C:\Python36-32\lib\site-packages\gspread\client.py", line 52, in login
    self.auth.refresh(http)
  File "C:\Python36-32\lib\site-packages\oauth2client\client.py", line 668, in refresh
    self._refresh(http.request)
  File "C:\Python36-32\lib\site-packages\oauth2client\client.py", line 873, in _refresh
    self._do_refresh_request(http_request)
  File "C:\Python36-32\lib\site-packages\oauth2client\client.py", line 905, in _do_refresh_request
    self.token_uri, method='POST', body=body, headers=headers)
  File "C:\Python36-32\lib\site-packages\httplib2\__init__.py", line 1322, in request
    (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
  File "C:\Python36-32\lib\site-packages\httplib2\__init__.py", line 1072, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "C:\Python36-32\lib\site-packages\httplib2\__init__.py", line 1002, in _conn_request
    raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
httplib2.ServerNotFoundError: Unable to find the server at accounts.google.com***

经过一些研究,我觉得这是由于我的代理设置造成的,但我无法弄清楚我需要做些什么来修复它。我也明白 python 库 socks 可能会有所帮助,但我又一次被难住了

任何帮助将不胜感激

提前致谢

【问题讨论】:

    标签: python proxy pycharm google-sheets-api httplib2


    【解决方案1】:

    虽然很久以前有人问过这个问题,但我想分享对我有用的修复方法。

    当我使用带有协议的主机时发生错误

    httplib2.ProxyInfo(
        proxy_type=httplib2.socks.PROXY_TYPE_HTTP,
        proxy_host='https://proxy.prod.com',
    )
    

    删除协议解决了问题:

    httplib2.ProxyInfo(
        proxy_type=httplib2.socks.PROXY_TYPE_HTTP,
        proxy_host='proxy.prod.com',
    )
    

    【讨论】:

      猜你喜欢
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 2017-03-29
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多