Python 属性错误:';模块';对象没有属性';HTTPError';
我使用spread python库创建了一个工作表类。这是我的密码:Python 属性错误:';模块';对象没有属性';HTTPError';,python,gspread,Python,Gspread,我使用spread python库创建了一个工作表类。这是我的密码: from oauth2client.service_account import ServiceAccountCredentials import time import gspread import requests import os DIRNAME = os.path.dirname(__file__) class Wksh: credentials_google_sheet = ServiceAccoun
from oauth2client.service_account import ServiceAccountCredentials
import time
import gspread
import requests
import os
DIRNAME = os.path.dirname(__file__)
class Wksh:
credentials_google_sheet = ServiceAccountCredentials.from_json_keyfile_name(os.path.join(DIRNAME, 'credentials/gs_credentials.json'),['https://spreadsheets.google.com/feeds'])
gc = gspread.authorize(credentials_google_sheet)
worksheet_id = None
sheet_name = None
sheet = None
def __init__(self,wksh_id,sh_name):
while True:
try:
self.worksheet_id = wksh_id
self.sheet_name = sh_name
self.sheet = self.gc.open_by_key(wksh_id).worksheet(sh_name)
break
except (gspread.exceptions.HTTPError, gspread.exceptions.requests, gspread.exceptions.RequestError) as e:
if e[0] == 401:
self.gc.login()
elif e[0] == 500:
time.sleep(10)
else:
print 'init'
print e
break
except requests.exceptions.ConnectionError as e:
time.sleep(10)
except requests.exceptions.ChunkedEncodingError as e:
time.sleep(20)
def write(self,cell,value):
while True:
try:
self.sheet.update_acell(cell,value)
break
except (gspread.exceptions.HTTPError, gspread.exceptions.requests, gspread.exceptions.RequestError) as e:
if e[0] == 401:
self.gc.login()
elif e[0] == 500:
time.sleep(10)
else:
print 'write'
print e
break
except requests.exceptions.ConnectionError as e:
time.sleep(10)
except requests.exceptions.ChunkedEncodingError as e:
time.sleep(20)
这可以很好地工作,但无论何时出现请求错误,即使我试图捕获我得到的错误:
AttributeError: 'module' object has no attribute 'RequestError' or
AttributeError: 'module' object has no attribute 'HTTPError'
为什么会这样?我是否需要在异常之前使用self.
谢谢删除了HTTPError检查gspread更改 在这里您可以看到所有可用的异常
HTTPError已删除检查gspread更改 在这里您可以看到所有可用的异常
好吧。也许你想要?嗯。也许你想要?嘿,我刚得到一个错误:AttributeError:'module'对象没有属性'APIError'。我该如何解决这个问题?请帮忙!!这是一行代码:除了gspread.exceptions.APIError作为e:我基本上捕获到了异常。我不知道我是否错过了一个导入。我已经从oauth2client.service\u帐户导入了gspread和ServiceAccountCredentials,请帮助!!我一直收到这个错误AttributeError:'模块'对象没有属性'APIError'嘿,我刚刚收到这个错误:AttributeError:'模块'对象没有属性'APIError'。我该如何解决这个问题?请帮忙!!这是一行代码:除了gspread.exceptions.APIError作为e:我基本上捕获到了异常。我不知道我是否错过了一个导入。我已经从oauth2client.service\u帐户导入了gspread和ServiceAccountCredentials,请帮助!!我一直收到此错误AttributeError:“module”对象没有属性“APIError”