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

Llama Index Google Docs Reader加载文档触发TypeError,寻求技术指导

解决Llama Index GoogleDocsReader加载文档时的TypeError(端口参数类型不匹配)

问题背景

运行Llama Index官方Google Docs演示Notebook,已获取完整字段的credentials.json,执行加载代码时触发TypeError: 'str' object cannot be interpreted as an integer,错误栈指向端口参数类型不匹配。

解决方案

1. 修正credentials.json中的端口类型

打开你的credentials.json,检查是否存在"port"字段:

  • 如果该字段的值是字符串格式(如"8080"),将其改为整数格式(8080),保存后重新运行代码。

2. 初始化GoogleDocsReader时手动指定整数端口

如果修改credentials.json无效,可在初始化阅读器时显式指定整数类型的端口:

from llama_index.readers.google import GoogleDocsReader
from google.oauth2.credentials import Credentials

# 加载本地credentials文件
creds = Credentials.from_authorized_user_file('credentials.json')
# 显式设置port为整数
reader = GoogleDocsReader(creds=creds, port=8080)
# 加载文档
document_ids = ["1q165nYvEXTT8ym4pN9lf7aatF-_VYc2ziaIGUBxtkvQ"]
documents = reader.load_data(document_ids=document_ids)

3. 升级依赖库版本

版本兼容问题也可能导致该错误,执行以下命令更新相关依赖:

pip install --upgrade google-auth-oauthlib google-api-python-client llama-index

错误原因说明

该错误本质是Google OAuth本地回调服务器尝试绑定端口时,传入了字符串类型参数,但socket接口要求端口必须是整数。常见触发场景包括:

  • credentials.json中的port字段被导出为字符串格式
  • Llama Index的GoogleDocsReader在解析credentials时未自动转换端口类型

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 21:46:04