gpt4 book ai didi

python - 如果我有一个except,我该如何重做?

转载 作者:行者123 更新时间:2023-12-03 21:57:39 25 4
gpt4 key购买 nike

我正在编写一个 刮刀使用 gspread 在 Google Sheets 中读写。
在代码的“写作”部分,我不得不添加一个 try-except因为一个 APIError由于写入的配额限制导致,所以当except被执行时,需要等待100秒然后继续。问题是它忽略了导致异常的项目,但它应该重复该项目

    def process_cpf_list(self):

# SKIP OVER COLUMN HEADING IN THE SPREADSHEET
cpfs = self.sheet.col_values(self.cpf_col)[1:]
bot_url = BOT()

for row, cpf in enumerate(cpfs):
nome, idade, beneficio, concessao, salario, bancos, bancocard, consig, card = bot_url.search_cpfs(cpf)

# UPDATE THE SHEET
print("Atualizando...")
try:
row = row + 2
self.sheet.update_cell(row, self.nome_col, nome)
self.sheet.update_cell(row, self.age_col, idade)
self.sheet.update_cell(row, self.beneficio_col, beneficio)
self.sheet.update_cell(row, self.concessao_col, concessao)
self.sheet.update_cell(row, self.salario_col, salario)
self.sheet.update_cell(row, self.bancos_col, bancos)
self.sheet.update_cell(row, self.bancocard_col, bancocard)
self.sheet.update_cell(row, self.consig_col, consig)
self.sheet.update_cell(row, self.card_col, card)
print('Cliente atualizado!')
except APIError:
print('Esperando para atualizar...')
time.sleep(100)
continue


cpf_updater = CpfSearch('TESTE')
cpf_updater.process_cpf_list()

最佳答案

while True:
try:
# do some stuff
break # we didn't hit the exception, exit the loop
except APIError:
# handle the exception...

关于python - 如果我有一个except,我该如何重做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61210291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com