2017-06-27 54 views
1

scope = ['https://spreadsheets.google.com/feeds'] creds = ServiceAccountCredentials.from_json_keyfile_name('NFL Redraft-e021dc0d5969.json', scope) client = gspread.authorize(creds) Gspread,PythonAnywhere:「OSERROR:[錯誤101]網絡不可達」 - 試圖連接到谷歌表

此代碼是我的本地機器上運作良好,但它未能在PythonAnywhere與OSError: [Errno 101] Network is unreachable

任何想法如何解決?它試圖運行它的時候只有10次運行。我已經嘗試了控制檯和ipython。 Gspread和Praw是最新的。

OSError         Traceback (most recent call last) 
 
<ipython-input-1-148cc5cb6e1b> in <module>() 
 
    1303 players, draft_pick_assignments, ordered_picks, positions = initialize_draft() 
 
    1304 pick_string, round_up, pick_up = pick_up_next() 
 
-> 1305 x, x, x, comments, messages = authenticate_google() 
 
    1306 comments_replied_to = restore_from_sheets(comments) 
 
    1307 messages_processed = restore_from_sheets(messages) 
 
<ipython-input-1-148cc5cb6e1b> in authenticate_google() 
 
    39  scope = ['https://spreadsheets.google.com/feeds'] 
 
    40  creds = ServiceAccountCredentials.from_json_keyfile_name('NFL Redraft-e021dc0d5969.json', scope) 
 
---> 41  client = gspread.authorize(creds) 
 
    42 
 
    43  sht = client.open("Redraft Test") 
 
/home/jj2807/.local/lib/python3.5/site-packages/gspread/client.py in authorize(credentials) 
 
    400  """ 
 
    401  client = Client(auth=credentials) 
 
--> 402  client.login() 
 
    403  return client 
 
/home/jj2807/.local/lib/python3.5/site-packages/gspread/client.py in login(self) 
 
    59 
 
    60    http = httplib2.Http() 
 
---> 61    self.auth.refresh(http) 
 
    62 
 
    63   self.session.add_header('Authorization', "Bearer " + self.auth.access_token) 
 

 
/usr/local/lib/python3.5/dist-packages/oauth2client/client.py in refresh(self, http) 
 
    558     request. 
 
    559   """ 
 
--> 560   self._refresh(http.request) 
 
    561 
 
    562  def revoke(self, http): 
 

 
/usr/local/lib/python3.5/dist-packages/oauth2client/client.py in _refresh(self, http_request) 
 
    763   """ 
 
    764   if not self.store: 
 
--> 765    self._do_refresh_request(http_request) 
 
    766   else: 
 
    767    self.store.acquire_lock() 
 

 
/usr/local/lib/python3.5/dist-packages/oauth2client/client.py in _do_refresh_request(self, http_request) 
 
    795   logger.info('Refreshing access_token') 
 
    796   resp, content = http_request(
 
--> 797    self.token_uri, method='POST', body=body, headers=headers) 
 
    798   content = _helpers._from_bytes(content) 
 
    799   if resp.status == http_client.OK: 
 

 
/usr/local/lib/python3.5/dist-packages/httplib2/__init__.py in request(self, uri, method, body, headers, redirections, connection_type) 
 
    1312      content = b"" 
 
    1313     else: 
 
-> 1314      (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey) 
 
    1315   except Exception as e: 
 
    1316    if self.force_exception_to_status_code: 
 

 
/usr/local/lib/python3.5/dist-packages/httplib2/__init__.py in _request(self, conn, host, absolute_uri, request_uri, method, body, headers, redirections, cachekey) 
 
    1062    auth.request(method, request_uri, headers, body) 
 
    1063 
 
-> 1064   (response, content) = self._conn_request(conn, request_uri, method, body, headers) 
 
    1065 
 
    1066   if auth: 
 

 
/usr/local/lib/python3.5/dist-packages/httplib2/__init__.py in _conn_request(self, conn, request_uri, method, body, headers) 
 
    985    try: 
 
    986     if conn.sock is None: 
 
--> 987      conn.connect() 
 
    988     conn.request(method, request_uri, body, headers) 
 
    989    except socket.timeout: 
 

 
/usr/lib/python3.5/http/client.py in connect(self) 
 
    1250    "Connect to a host on a given (SSL) port." 
 
    1251 
 
-> 1252    super().connect() 
 
    1253 
 
    1254    if self._tunnel_host: 
 

 
/usr/lib/python3.5/http/client.py in connect(self) 
 
    847   """Connect to the host and port specified in __init__.""" 
 
    848   self.sock = self._create_connection(
 
--> 849    (self.host,self.port), self.timeout, self.source_address) 
 
    850   self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) 
 
    851 
 

 
/usr/lib/python3.5/socket.py in create_connection(address, timeout, source_address) 
 
    709 
 
    710  if err is not None: 
 
--> 711   raise err 
 
    712  else: 
 
    713   raise error("getaddrinfo returns an empty list") 
 

 
/usr/lib/python3.5/socket.py in create_connection(address, timeout, source_address) 
 
    700    if source_address: 
 
    701     sock.bind(source_address) 
 
--> 702    sock.connect(sa) 
 
    703    return sock 
 
    704

回答

3

您使用的是舊版本gspread的是對PythonAnywhere預裝和不承認代理設置,讓你無法連接了。嘗試使用更新版本的gspread。

1

不幸的是,你可能會升級到付費帳戶來解決這個問題。根據Python的任何地方工作人員,免費賬戶通過代理,以限制他們的API白名單。 Gspread顯然將嘗試通過代理一次去,繞過它下。這是從另一個線程的工作人員:

「這甚至會發生代碼相同的 - 那就是,完全相同的代碼可能工作一天,然後不是下一個不幸的是,只有我們知道的是修復。切換到付費帳戶。「

https://www.pythonanywhere.com/forums/topic/11822/