2016-01-13 19 views
10

से शुरू करने से Django को रोकता है मेरे पास एक Django (1.9.1) प्रोजेक्ट है जो ठीक से काम कर रहा था जब तक कि मैंने अपने ऐप्स में से किसी एक को Google Calendar API documentation द्वारा प्रदान किया गया कोड जोड़ा।Google कैलेंडर एपीआई

इस कोड को भी मेरी आभासी env में ठीक काम करता है जब मैं स्टैंडअलोन मोड में चलाने के लिए, लेकिन जब मैं Django परियोजना के अंदर कोड का उपयोग करने का प्रयास करते समय मैं चलाने "अजगर manage.py runserver" मैं यह संदेश प्राप्त:

./manage.py runserver 
Performing system checks... 

usage: manage.py [-h] [--auth_host_name AUTH_HOST_NAME] 
       [--noauth_local_webserver] 
       [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]] 
       [--logging_level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] 
manage.py: error: unrecognized arguments: runserver 

यह त्रुटि तब होती है जब मैं makemigrations या विस्थापित को चलाने के लिए प्रयास करें।

स्पष्ट रूप से त्रुटि मुझे बता रही है कि क्या करना है, लेकिन मैं वास्तव में इसे समझ नहीं पा रहा हूं।

सुरक्षित रहने के लिए, यहाँ कोड है कि मैं चलाने के लिए कोशिश कर रहा हूँ है:

from __future__ import print_function 
import httplib2 
import os 

from apiclient import discovery 
import oauth2client 
from oauth2client import client 
from oauth2client import tools 


try: 
    import argparse 
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() 
except ImportError: 
    flags = None 

SCOPES = 'https://www.googleapis.com/auth/calendar' 
CLIENT_SECRET_FILE = 'client_secret.json' 
APPLICATION_NAME = 'Google Calendar API Python Quickstart' 


def get_credentials(): 
    """Gets valid user credentials from storage. 

    If nothing has been stored, or if the stored credentials are invalid, 
    the OAuth2 flow is completed to obtain the new credentials. 

    Returns: 
     Credentials, the obtained credential. 
    """ 
    home_dir = os.path.expanduser('~') 
    credential_dir = os.path.join(home_dir, '.credentials') 
    if not os.path.exists(credential_dir): 
     os.makedirs(credential_dir) 
    credential_path = os.path.join(credential_dir, 
            'calendar-python-quickstart.json') 

    store = oauth2client.file.Storage(credential_path) 
    credentials = store.get() 
    if not credentials or credentials.invalid: 
     flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) 
     flow.user_agent = APPLICATION_NAME 
     if flags: 
      credentials = tools.run_flow(flow, store, flags) 
     else: # Needed only for compatibility with Python 2.6 
      credentials = tools.run(flow, store) 
     print('Storing credentials to ' + credential_path) 
    return credentials 

def add_event(event): 
    """Shows basic usage of the Google Calendar API. 

    Creates a Google Calendar API service object and outputs a list of the next 
    10 events on the user's calendar. 
    """ 
    credentials = get_credentials() 
    http = credentials.authorize(httplib2.Http()) 
    service = discovery.build('calendar', 'v3', http=http) 

    print("Adding to calendar") 


    event = service.events().insert(calendarId='<email>', body=event).execute() 
    print('Event created: %s' % (event.get('htmlLink'))) 
+0

जिसमें फ़ाइल ऊपर कोड है इसमें लिखा हुआ? – JRodDynamite

+0

मेरे Django ऐप्स में से किसी एक की रूट में स्थित एक अजगर फ़ाइल में। क्या आप यही पूछ रहे हैं, @JasonEstibeiro? –

+0

यह स्थान है, @JasonEstibeiro: https://github.com/hannonq/bcc264-email/tree/master/push_email ऊपर वर्णित फ़ाइल "calendarhandler.py" है, जिसे "utils" कहा जाता है .py " –

उत्तर

14

बदलें:

साथ
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() 

flags = tools.argparser.parse_args([]) 
+1

मुझे जीमेल एपीआई का उपयोग करने के साथ एक ही समस्या का सामना करना पड़ा। यह समाधान सही है! – InamTaj

+1

बिल्कुल सही समाधान, मैं काफी निराश महसूस कर रहा था - मेरे जीवन को बचाया :) – shippi

संबंधित मुद्दे