我正在使用pygsheets与谷歌电子表格和驱动器工作。我需要上传10000多个文件到公司驱动器,但每次我使用服务帐户,我会收到一个错误后,上传200个ish文件。错误如下:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
我检查了我的云控制台。我不会过度使用对每个给定时间的请求数量的限制。我在每次请求之间等待10秒。
附上相关代码如下:
def upload_cluster(sheets, cluster_array):
max_global = 0
max_local = 0
max_traffic = 0
sum_global = 0
sum_local = 0
sum_traffic = 0
keywords = len(cluster_array)
cluster_name = ''
for elem in cluster_array:
if elem.get('Global volume') >= max_global:
cluster_name = elem.get('Keyword')
max_global = elem.get('Global volume')
if elem.get('Volume') > max_local:
max_local = elem.get('Volume')
if elem.get('Traffic potential') > max_traffic:
max_traffic = elem.get('Traffic potential')
sum_global += elem.get('Global volume')
sum_local += elem.get('Volume')
sum_traffic += elem.get('Traffic potential')
book = sheets.create(title=re.sub('\"', '', cluster_name), folder='FOLDER_ID')
link = f'HYPERLINK(\"https://docs.google.com/spreadsheets/d/{book.id}\",\"{cluster_name}\")'
dataframe = pandas.DataFrame(cluster_array)
out_sheet = book.worksheet(property='index', value=0)
out_sheet.set_dataframe(df=dataframe, start='A1', extend=True, copy_head=True, copy_index=False)
cluster_summary = {
'Cluster': link,
'Volume': sum_local,
'Global volume': sum_global,
'Traffic potential': sum_traffic,
'Max volume': max_local,
'Max global volume': max_global,
'Max traffic potential': max_traffic,
'Queries': keywords
}
return cluster_summary
def main():
gsheets = pygsheets.authorize(service_account_file='service-account.json')
for i in range(len(output_keywords) - 1):
if not output_keywords[i].get('Clustered'):
cluster = []
cluster.append(output_keywords[i])
cluster_max = get_vol(output_keywords[i].get('Global volume'))
cluster_urls = output_keywords[i].get('URLs')
output_keywords[i]['Clustered'] = True
print(f'Added to cluster: {cluster[-1]}')
for j in range(len(output_keywords)):
if not output_keywords[j].get('Clustered'):
if len(set(cluster_urls) & set(output_keywords[j].get('URLs'))) >= 4:
cluster.append(output_keywords[j])
output_keywords[j]['Clustered'] = True
print(f'Added to cluster: {cluster[-1]}')
print('Uploading cluster...')
clusters.append(upload_cluster(gsheets, cluster))
sleep(5)
print(f'Uploaded: {clusters[-1]}')
cluster = []
我也尝试过通过客户端机密授权,这似乎很好,但不幸的是,我无法在文件夹中看到上传的文件。
服务帐户可以访问驱动器文件夹。
发布于 2022-03-02 20:15:23
经过更多的测试后,我注意到该脚本会阻塞一个特定的文件,因为该文件的名称中包含了'
。在使用RegEx从文件名中删除'
之后,它没有阻塞。很奇怪,但没问题。有人想过为什么会发生这种事吗?我以为Google没有禁止命名文件的字符。
https://stackoverflow.com/questions/71209179
复制相似问题