首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Pygsheets:不能上传超过200个ish文件来使用Google帐户来驱动。获取403错误

Pygsheets:不能上传超过200个ish文件来使用Google帐户来驱动。获取403错误
EN

Stack Overflow用户
提问于 2022-02-21 15:46:00
回答 1查看 63关注 0票数 0

我正在使用pygsheets与谷歌电子表格和驱动器工作。我需要上传10000多个文件到公司驱动器,但每次我使用服务帐户,我会收到一个错误后,上传200个ish文件。错误如下:

代码语言:javascript
运行
复制
 {
 "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秒。

附上相关代码如下:

代码语言:javascript
运行
复制
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 = []

我也尝试过通过客户端机密授权,这似乎很好,但不幸的是,我无法在文件夹中看到上传的文件。

服务帐户可以访问驱动器文件夹。

EN

Stack Overflow用户

回答已采纳

发布于 2022-03-02 20:15:23

经过更多的测试后,我注意到该脚本会阻塞一个特定的文件,因为该文件的名称中包含了'。在使用RegEx从文件名中删除'之后,它没有阻塞。很奇怪,但没问题。有人想过为什么会发生这种事吗?我以为Google没有禁止命名文件的字符。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71209179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档