How to solve gateway time-out while connecting to google calendar api?

I am trying to connect to google calendar Api using Documentation . This works on local host and I am able to retrieve events from the user's google calendar. After hosting the website using apache, I can see all the pages live but One of the pages is connecting to the google calendar api and this page says 504 Gateway Time-out.

location of credentials2.json

ProjectName
     ----   myapp1
     ----   myapp2
     ----   ProjectName
     ----   manage.py
     ----   credentails2.json



def connect_google_api():
    creds = None
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json')
    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('/var/www/FolderName/ProjectName/credentials2.json',SCOPES)
            creds = flow.run_local_server(port=0)
        
        with open('token.json','w') as token:
            token.write(creds.to_json())
    service = build('calendar','v3',credentials=creds)

I am thinking that there is some problem while reading credentails2.json. Can any one point me where I am making mistake?

Back to Top