You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Adobe PDF Extract API(Python)入门遇ValueError:client_id不能为空

解决Adobe PDF Extract API Python版client_id不能为空的问题

问题场景

按照Adobe PDF Extract API官方Python快速开始步骤操作,运行extract.py时触发如下报错:

credentials = Credentials.service_principal_credentials_builder().with_client_id(os.getenv('PDF_SERVICES_CLIENT_ID')).with_client_secret(os.getenv('PDF_SERVICES_CLIENT_SECRET')).build()
  File "/Users/tomr/Library/Python/3.9/lib/python/site-packages/adobe/pdfservices/operation/auth/service_principal_credentials.py", line 82, in build
    return ServicePrincipalCredentials(self._client_id, self._client_secret)
  File "/Users/tomr/Library/Python/3.9/lib/python/site-packages/adobe/pdfservices/operation/auth/service_principal_credentials.py", line 28, in __init__
    self._client_id = _is_valid(client_id, 'client_id')
  File "/Users/tomr/Library/Python/3.9/lib/python/site-packages/adobe/pdfservices/operation/auth/credentials.py", line 17, in _is_valid
    raise ValueError(f'{name} must not be blank')
ValueError: client_id must not be blank

已将pdfservices-api-credentials.json放在Python文件同目录,手动输入ID和密钥后问题依旧。

解决方案

1. 改用JSON文件加载凭证

官方示例默认从环境变量读取凭证,但如果已经有pdfservices-api-credentials.json,直接用文件加载更可靠,替换原凭证构建代码:

from adobe.pdfservices.operation.auth.credentials import Credentials

# 替换原来的service_principal_credentials_builder代码
credentials = Credentials.from_file("pdfservices-api-credentials.json")
  • 确保运行脚本时的当前工作目录是extract.py所在目录,否则需要传入JSON文件的绝对路径。

2. 检查手动输入的完整性

如果坚持手动输入凭证,需注意:仅传入client_id和client_secret可能不够,还需补充组织ID和账号ID(可从JSON文件中获取),完整代码示例:

credentials = Credentials.service_principal_credentials_builder()
    .with_client_id("你的实际Client ID")
    .with_client_secret("你的实际Client Secret")
    .with_organization_id("你的组织ID")
    .with_account_id("你的账号ID")
    .build()
  • 确认替换掉所有os.getenv()调用,不要混合使用环境变量和手动输入。

3. 验证JSON文件的正确性

检查pdfservices-api-credentials.json的格式和内容:

  • 确保文件名拼写完全正确,无大小写错误。
  • 确认JSON结构正确,client_credentials下的client_id和client_secret字段无拼写错误(比如不要写成clientId),示例正确结构:
{
  "client_credentials": {
    "client_id": "你的Client ID",
    "client_secret": "你的Client Secret"
  },
  "service_account_credentials": {
    "organization_id": "你的组织ID",
    "account_id": "你的账号ID",
    "private_key_file": "private.key"
  }
}

4. 检查环境变量加载(如果仍用环境变量方式)

若继续使用环境变量,需确认:

  • 终端中已正确设置环境变量:
    export PDF_SERVICES_CLIENT_ID="你的Client ID"
    export PDF_SERVICES_CLIENT_SECRET="你的Client Secret"
    
  • 运行脚本的终端会话是设置环境变量后的会话,不要在设置前的会话中运行脚本。

内容的提问来源于stack exchange,提问作者tom roddick

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 20:23:13