python - Python google 电子表格代码从命令行运行,但不是从 Web 脚本运行
问题描述
我正在尝试从 python 访问 google 工作表,并且在从命令行运行时工作正常。
#!C:/Users/uwe/AppData/Local/Programs/Python/Python37-32/python
print('Content-type: text/html\r\n')
import gspread
from oauth2client.service_account import ServiceAccountCredentials
尝试从本地主机运行它时出现错误
=> 18 import gspread
19 from oauth2client.service_account import ServiceAccountCredentials
20
gspread undefined
C:\Users\uwe\AppData\Local\Programs\Python\Python37-32\lib\site-packages\gspread\__init__.py in <module>()
14
15
=> 16 from .auth import oauth, service_account, service_account_from_dict
17 from .client import Client
18 from .models import Spreadsheet, Worksheet, Cell
oauth undefined, service_account undefined, service_account_from_dict undefined
C:\Users\uwe\AppData\Local\Programs\Python\Python37-32\lib\site-packages\gspread\auth.py in <module>()
45
46
=> 47 DEFAULT_CONFIG_DIR = get_config_dir()
48
49 DEFAULT_CREDENTIALS_FILENAME = os.path.join(
DEFAULT_CONFIG_DIR undefined, get_config_dir = <function get_config_dir>
C:\Users\uwe\AppData\Local\Programs\Python\Python37-32\lib\site-packages\gspread\auth.py in get_config_dir(config_dir_name='gspread', os_is_windows=True)
38 """
39 if os_is_windows:
=> 40 return os.path.join(os.environ["APPDATA"], config_dir_name)
41 else:
42 return os.path.join(
global os = <module 'os' from 'C:\\Users\\uwe\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\os.py'>, os.path = <module 'ntpath' from 'C:\\Users\\uwe\\AppData\\...\\Programs\\Python\\Python37-32\\lib\\ntpath.py'>, os.path.join = <function join>, os.environ = environ({'HTTP_HOST': 'localhost', 'HTTP_CONNECT...readsheet.py', 'SCRIPT_NAME': '/spreadsheet.py'}), config_dir_name = 'gspread'
C:\Users\uwe\AppData\Local\Programs\Python\Python37-32\lib\os.py in __getitem__(self=environ({'HTTP_HOST': 'localhost', 'HTTP_CONNECT...readsheet.py', 'SCRIPT_NAME': '/spreadsheet.py'}), key='APPDATA')
676 except KeyError:
677 # raise KeyError with the original key value
=> 678 raise KeyError(key) from None
679 return self.decodevalue(value)
680
builtin KeyError = <class 'KeyError'>, key = 'APPDATA'
KeyError: 'APPDATA'
args = ('APPDATA',)
with_traceback = <built-in method with_traceback of KeyError object>
我错过了什么?(Python新手,Win10,Apache2.4)
解决方案
推荐阅读
- mysql - 如何使用 ST_contains 从 MySQL 8 中的表中进行选择?
- javascript - 如何删除以前的
在显示另一个之后
?
- sublimetext2 - Sublime Text 2 - 包控制错误
- spring - 从 springboot 2.0.2 迁移到 2.2.2 时出现 JSON 解散问题
- python - Python - 使用文件引导程序 SuperCollider
- javascript - 将 socket.io 封装在一个类中
- mysql - Logstash 聚合重置值
- reactjs - create-react-app:没有使用 create-react-app 错误/启动脚本提供的模板(即使在删除全局安装的 create-react-app 之后)
- linux - 从目录中的文本文件创建新文件并插入文本
- list - Ansible根据其他项目列表创建项目列表