首页 > 解决方案 > 为什么我不能用 cmd 运行 python 程序?(但是,使用 Visual Estudio Code 是的)

问题描述

我不能用 cmd 运行 python 程序。

这是我的程序:

from __future__ import print_function
import getpass
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from apiclient.http import MediaFileUpload



# If modifying these scopes, delete the file token.json.
SCOPES = 'https://www.googleapis.com/auth/drive'
User = getpass.getuser()
print ("#---------------------------------------------------------")
print ("                   PROGRAMA PARA SUBIR                    ")
print ("#---------------------------------------------------------")
store = file.Storage('token.json')
creds = store.get()
drive = build('drive', 'v3', http=creds.authorize(Http()))
file_metadata = {'name': input(str("Introduce como se quiere llamar tu archivo en la nube (intruduce 
la extensión) EJEMPLO: photo.jpg o Video.mp4 ----->  "))}
media = MediaFileUpload('C:/Users/' + User + '/Desktop/' + input(str("¿Como se llama el archivo q 
quieres subir?----->   ")),
                    mimetype=input(str("Introduce el tipo de archivo que es. EJEMPLO: executable/exe. 
Primero de que tipo es, una / y despues la extensión. Y ten en cuenta q el tipo de archivo tiene q 
estar en ingles---->  ")))
file = drive.files().create(body=file_metadata,
                                media_body=media,
                                fields='id').execute()
print ('File ID: %s' % file.get('id'))

这是错误(在 CMD 中):回溯(最近一次调用最后一次):文件“C:\Users\Jose Maria\Desktop\Programación\Python\Subir.py”,第 27 行,在 drive = (build('drive ', 'v3', http=creds.authorize(Http()))) AttributeError: 'NoneType' 对象没有属性 'authorize'

标签: python

解决方案


推荐阅读