Erreur de syntaxe Python
Beranrd74
Messages postés
1
Date d'inscription
Statut
Membre
Dernière intervention
-
hippy -
hippy -
Bonjour,
Je suis nouveau en programmation[/code] Python et je rencontre le problème suivant :
Traceback (most recent call last):
File "/home/bernard/quickstart/quickinsert.py", line 75, in <module>
event = service.events().insert(calendarId='primary', body=event).execute()
NameError: name 'service' is not defined
Avec mes remerciements pour votre aide
Mon code :
Je suis nouveau en programmation[/code] Python et je rencontre le problème suivant :
Traceback (most recent call last):
File "/home/bernard/quickstart/quickinsert.py", line 75, in <module>
event = service.events().insert(calendarId='primary', body=event).execute()
NameError: name 'service' is not defined
Avec mes remerciements pour votre aide
Mon code :
from __future__ import print_function import datetime import pickle import os.path import sys reload(sys) sys.setdefaultencoding('utf8') from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request # If modifying these scopes, delete the file token.pickle. # SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] SCOPES = ['https://www.googleapis.com/auth/calendar'] def main(): creds = None # The file token.pickle stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', SCOPES) creds = flow.run_local_server() # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) service = build('calendar', 'v3', credentials=creds) # Call the Calendar API now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time events_result = service.events().list(calendarId='primary', timeMin=now, maxResults=200, singleEvents=True, orderBy='startTime').execute() events = events_result.get('items', []) # fichier=open("/home/bernard/quickstart/bernardinsert.txt","r") event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': 'lpage@example.com'}, {'email': 'sbrin@example.com'}, ], 'reminders': { 'useDefault': False, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10}, ], }, } event = service.events().insert(calendarId='primary', body=event).execute() if __name__ == '__main__': main()
Configuration: Linux / Firefox 66.0
A voir également:
- Erreur de syntaxe Python
- Citizen code python - Accueil - Outils
- Erreur 0x80070643 - Accueil - Windows
- Erreur 0x80070643 Windows 10 : comment résoudre le problème de la mise à jour KB5001716 - Accueil - Windows
- Erreur 4101 france tv - Forum Lecteurs et supports vidéo
- J'aime par erreur facebook notification - Forum Facebook