我收到这个错误---> EOFError:读取一行时的EOF

时间:2015-07-16 13:49:04

标签: python-2.7 google-app-engine httplib2

每次运行代码时都会出现此错误代码= raw_input('输入验证码:')。strip()

EOFError:读取一行时的EOF  我每次运行代码时都会收到此错误代码= raw_input('输入验证码:')。strip()

EOFError:读取行时的EOF

import httplib2

from apiclient import errors
from apiclient.discovery import build
from oauth2client.client import OAuth2WebServerFlow


# Copy your credentials from the console
CLIENT_ID = '***************.apps.googleusercontent.com'
CLIENT_SECRET = '******************VaHO'

# Check https://developers.google.com/admin-sdk/directory/v1/guides/authorizing for all available scopes
OAUTH_SCOPE = 'https://www.googleapis.com/auth/admin.directory.user'

# Redirect URI for installed apps
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'

# Run through the OAuth flow and retrieve credentials
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI)
authorize_url = flow.step1_get_authorize_url()
print 'Go to the following link in your browser: ' + authorize_url
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)

# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)

directory_service = build('admin', 'directory_v1', http=http)

all_users = []
page_token = None
params = {'customer': 'my_customer'}

while True:
  try:
    if page_token:
      params['pageToken'] = page_token
    current_page = directory_service.users().list(**params).execute()

    all_users.extend(current_page['users'])
    page_token = current_page.get('nextPageToken')
    if not page_token:
      break
  except errors.HttpError as error:
    print 'An error occurred: %s' % error
    break

for user in all_users:
  print user['primaryEmail']`enter code here`

1 个答案:

答案 0 :(得分:0)

尝试通过命令行运行它,而不是通过IDE运行。当我通过IDE运行应用程序时出现同样的错误。