python - How do I include the Kaggle api key into a google cloud function so that the Kaggle api can find it? - Stack Overflow

I'm trying to write a google cloud function that automatically downloads data from a certain kaggl

I'm trying to write a google cloud function that automatically downloads data from a certain kaggle data set and upload it to a google cloud bucket. No matter how I try to include my kaggle api key in my google cloud function, the kaggle api can't find it!

I uploaded my kaggle api key to the secret manager and I wrote some code to write the key value into a file stored in /tmp, and set KAGGLE_CONFIG_DIR to /tmp. I granted the cloud function secret manager admin permissions and created added a runtime service account with permission to access the kaggle key as well just to make sure

I reference the secret via a mount path that I set here

First I tried just setting KAGGlE_CONFIG_DIR to the mount path, but that didn't work:

os.environ["KAGGLE_CONFIG_DIR"] = "/.kaggle"

Then I tried to write the key to /tmp, and set KAGGlE_CONFIG_DIR to /tmp and that didn't work either.

def get_kaggle_api_key():
    kaggle_key_path = "/.kaggle/kaggle.json"  

    #read the kaggle key
    with open(kaggle_key_path, 'r') as f:
        kaggle_api_key = f.read().strip()

    #save the key to /tmp/
    kaggle_config_path = "/tmp/kaggle.json" 
    with open(kaggle_config_path, 'w') as f:
        json.dump(json.loads(kaggle_api_key), f)

    os.environ["KAGGLE_CONFIG_DIR"] = "/tmp"

I always get this error:

OSError: Could not find kaggle.json. Make sure it's located in /www-data-home/.config/kaggle. Or use the environment method. See setup instructions at /

The setup instructions don't help, they just say to set KAGGLE_CONFIG_DIR to where the key is stored, which I did.

This is my first time trying to write a cloud function to access an api, and I'm not really sure what I'm doing. Please help!

I'm trying to write a google cloud function that automatically downloads data from a certain kaggle data set and upload it to a google cloud bucket. No matter how I try to include my kaggle api key in my google cloud function, the kaggle api can't find it!

I uploaded my kaggle api key to the secret manager and I wrote some code to write the key value into a file stored in /tmp, and set KAGGLE_CONFIG_DIR to /tmp. I granted the cloud function secret manager admin permissions and created added a runtime service account with permission to access the kaggle key as well just to make sure

I reference the secret via a mount path that I set here

First I tried just setting KAGGlE_CONFIG_DIR to the mount path, but that didn't work:

os.environ["KAGGLE_CONFIG_DIR"] = "/.kaggle"

Then I tried to write the key to /tmp, and set KAGGlE_CONFIG_DIR to /tmp and that didn't work either.

def get_kaggle_api_key():
    kaggle_key_path = "/.kaggle/kaggle.json"  

    #read the kaggle key
    with open(kaggle_key_path, 'r') as f:
        kaggle_api_key = f.read().strip()

    #save the key to /tmp/
    kaggle_config_path = "/tmp/kaggle.json" 
    with open(kaggle_config_path, 'w') as f:
        json.dump(json.loads(kaggle_api_key), f)

    os.environ["KAGGLE_CONFIG_DIR"] = "/tmp"

I always get this error:

OSError: Could not find kaggle.json. Make sure it's located in /www-data-home/.config/kaggle. Or use the environment method. See setup instructions at https://github/Kaggle/kaggle-api/

The setup instructions don't help, they just say to set KAGGLE_CONFIG_DIR to where the key is stored, which I did.

This is my first time trying to write a cloud function to access an api, and I'm not really sure what I'm doing. Please help!

Share Improve this question edited Nov 15, 2024 at 22:04 Doug Stevenson 319k36 gold badges456 silver badges473 bronze badges asked Nov 15, 2024 at 21:58 Sean MacInnisSean MacInnis 11 silver badge
Add a comment  | 

1 Answer 1

Reset to default 1

I'm not a Kaggle user but hopefully this example will help.

There are 3 (possibly 2) steps but importantly you must create a volume and then create a volume mount:

  1. Create an environment variable for KAGGLE_CONFIG_DIR
  2. Create a Volume (e.g. KAGGLE-CONFIG-DIR) using the Secret
  3. Create a Volume Mount (e.g. /.kaggle)

Set an environment variable (KAGGLE_CONFIG_DIR) to /.kaggle:

Create a Volume:

Create a Container Volume Mount:

And some Python:

@functions_framework.http
def root(request):
    # Get the value from the environment
    kaggle_config_dir = os.getenv("KAGGLE_CONFIG_DIR")

    # Open the file
    with open(f"{kaggle_config_dir}/kaggle.json", 'r') as file:
        content = file.read()
        # Return the content
        return f"{kaggle_config_dir}/kaggle.json: {content}:

Yields:

.kaggle/kaggle.json: {"your":"JSON"}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745674566a4639608.html

相关推荐

  • windows蓝牙驱动开发-蓝牙无线电重置和恢复

    蓝牙无线电重置和恢复是 Windows 10 版本 1803 及更高版本中的一种技术,为蓝牙无线电引入了可靠的重置和恢复机制。 此机制使蓝牙无线电能够从导致故障、连接中断或对操作命令无响应的硬件故障中恢复。 目标是自动

    2小时前
    10
  • 【合集】深入理解大容量SSD设计

    全文概览随着数据量的爆炸式增长,对SSD容量的需求也日益迫切。如何在有限的物理空间内,进一步提升SSD的存储容量,同时兼顾性能与成本,成为了业界亟待解决的关键问题。本文深入探讨了SSD架构设计中的核心要素——间接单元(IU)和动态随机存取存

    2小时前
    00
  • LLM 推理引擎之争:Ollama or vLLM ?

    Hello folks,我是 Luga,今天我们来聊一下人工智能应用场景 - 构建高效、灵活的计算架构的模型推理框架。 在人工智能领域,模型的推理能力是衡量其性能的核心指标之一,直接影响其在复杂任务中的表现。随着自然语言处理(NL

    1小时前
    10
  • JUC并发—6.AQS源码分析二

    大纲1.ReentractReadWriteLock的基本原理2.基于AQS实现的ReentractReadWriteLock3.ReentractReadWriteLock如何竞争写锁4.ReentractReadWriteLock如何竞

    1小时前
    10
  • 解码陪玩系统连麦技术:从音频传输到实时交互

    陪玩公众号 陪玩小程序陪玩app陪玩平台源码 陪玩平台搭建 游戏陪玩源码 线上游戏陪玩源码 线上游戏平台搭建线上游戏代练系统 下线付费搭子源码 线下家政平台 线下家政源码线下预约服务源码 陪玩陪聊系统源码 陪玩平台搭建 游戏陪玩系统,线

    1小时前
    00
  • Python+AI提示词出租车出行轨迹预测:梯度提升GBR、KNN、LR回归、随机森林融合及贝叶斯概率异常检测研究

    原文链接:tecdat?p=41693在当今数字化浪潮席卷全球的时代,城市交通领域的海量数据如同蕴藏着无限价值的宝藏等待挖掘。作为数据科学家,我们肩负着从复杂数据中提取关键信息、构建有效模型以助力决策的使命。我们团队承接并完成了一项极具挑

    1小时前
    00
  • 三代测序技术100问(2):PacBio 与 ONT,谁是你的长读长利器?

    在上一期(三代测序技术100问(1):NGS与第三代测序,如何做出明智选择?)中,我们厘清了二代与三代测序技术的适用边界,明确了选择需“因题施策”。然而,踏入三代测序的大门,新的抉择又摆在面前:目前市场上主流的长读长技术平台主要由两大阵营引

    1小时前
    00
  • Power BI 展示产品边际贡献

    SQLBI最近发布了一篇动态帕累托的文章,在帕累托曲线图表上增加图例,可以不对不同区域的客户贡献进行横向对比:来源 如果把X轴换成产品,该方案还可用来查看不同品类产品的边际贡献,进而对产品线规划进行改善。上图Computers Acces

    1小时前
    00
  • 一个让DevOps癫狂的项目一键部署数百个MCP服务器

    背景MCP(Model Context Protocol)是一种新兴的标准化协议,用于管理大型语言模型(LLM)与外部系统之间的上下文交互。随着 AI 技术的快速发展,越来越多的开发者需要将 LLMs 与各种外部工具、API 和数据源集成。

    1小时前
    00
  • CAN总线仿真工程开发流程及策略

    在汽车电子控制系统的开发过程中,ECU的仿真测试起着至关重要的作用。总线仿真工程作为ECU开发中的核心环节,它贯穿了整个开发过程,从需求分析到软件开发、软件测试,再到硬件验证和失效分析等多个阶段。一个合理的总线仿真工程开发流程和科学的开发策

    1小时前
    00
  • minio使用简介

    在云原生和微服务时代,对象存储已成为存储非结构化数据(如图片、日志、备份等)的首选方案。MinIO 是一款高性能、兼容 S3 API 的开源对象存储服务,而它的官方 Go SDK —— minio-go,则可以让你在 Go 语言项目中轻松集

    1小时前
    00
  • Andorid平台实现高性能低延迟的多路RTSP播放器

    ​在当今的视频监控、流媒体传输等领域,RTSP(Real Time Streaming Protocol)协议被广泛用于音视频数据的实时传输。为了满足多路 RTSP 流的同时播放需求,基于大牛直播SDK开发了一款功能丰富、性能稳定的多路 R

    1小时前
    00
  • 安利一个超强的linux脚本

    想像一个场景,你突然接手管理一个系统,之前对接的人没有留下任何材料,主机上也没有历史命令能够看到之前做了哪些操作。怎么办?今天介绍一个简单的脚本记录linux历史执行记录的方法,可以在现有主机上配置,然后后面主机初始化都配置上。Linux命

    51分钟前
    00
  • 迈向长上下文视频生成!NUS团队新作FAR同时实现短视频和长视频预测SOTA,代码已开源

    本文由 NUS ShowLab 主导完成。第一作者顾宇超为新加坡国立大学 ShowLab@NUS 在读博士生,研究方向是视觉生成,在 CVPR、ICCV、NeurIPS 等国际顶级会议与期刊上发表多篇研究成果。第二作者毛维嘉为新加坡国立大学

    43分钟前
    00
  • ICLR 2025杰出论文公布!中科大硕士、OpenAI漆翔宇摘桂冠

    新智元报道编辑:桃子 好困【新智元导读】一年一度ICLR 2025杰出论文开奖!普林斯顿、UBC、中科大NUS等团队的论文拔得头筹,还有Meta团队「分割一切」SAM 2摘得荣誉提名。刚刚,ICLR 2025杰出论文出炉了!今年共有三篇

    37分钟前
    00
  • MobileNetV2:面向移动端的高效神经网络架构革新——突破轻量化模型的设计边界

    我们倾向于将“移动”与更小、更高效的事物联系起来,所以我原本以为这个网络的设计会占用更少的计算资源,而这正是作者的目标。这篇论文描述了一种专为移动和资源受限环境量身定制的全新神经架构——MobileNetV2。他们强调了MobileNetV

    30分钟前
    00
  • 科研人狂喜!不用再到处找文献,这个神器让你轻松获取全网外文文献

    写论文时,你是否也有过这样的困扰?SCI - Hub?Library Genesis?几个数据库反复横跳,还是找不到想要的文献。想查最新的外文研究成果,却不知道该上哪个数据库,在各个平台间来回切换,浪费了大量时间和精力,结果还可能一无所获。

    16分钟前
    00
  • Java 实现 MCP Server 以及常用 MCP 服务分享

    MCP 前段时间在 AI 领域 引发了 广泛关注,特别是在 各大海内外技术社区 中,大家热烈讨论,热度非常高,本文将带领大家使用 java 语言实现一个 mcp,揭开 mcp 这神秘的面纱,本文最后也推荐给大家一些常用的 MCP 服务,开箱

    9分钟前
    00
  • 如何搭建一个高效安全的API开放平台:完整步骤指南

    在当今数字化时代,API(应用程序编程接口)已成为连接不同系统和服务的桥梁。一个设计良好的API开放平台能够为企业带来巨大的商业价值和技术优势。本文将详细介绍从零开始搭建一个API开放平台的完整步骤,涵盖技术选型、架构设计、安全防护和运维管

    6分钟前
    00
  • Java与C语言核心差异:从指针到内存管理的全面剖析

    【前言】 在计算机编程领域,Java和C语言都是极具影响力的编程语言。Java以其跨平台性、安全性和面向对象的特性广受欢迎;而C语言凭借对底层的强大操控能力,在系统开发、嵌入式领域占据重要地位。这两种语言在指针和内存管理方面存在显著差异,

    1分钟前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信